Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set Jenkins Variable in Jenkinsfile only if it is triggered by cron [duplicate]

I want to trigger a Jenkinsjob every 2nd Tuesday. What I learned so far, is that this is not possible that easy. So I was trying something like this:

stage('Setup build schedule') {
  properties([
    pipelineTriggers([
      cron('0 20 * * 2')
    ])
  ])
}

def build_number = env.BUILD_NUMBER as int
if ((build_number % 2) == 0) { 
... 
}

which is okay. But sometimes i also want to trigger this Multibranch-Pipeline Job by hand. Is it possible to set a variable only during the cron triggered start? Then I can check if this variable is set, and if not I know it is triggered by handy and proceed that way?

like image 301
FrostX Avatar asked Oct 18 '25 12:10

FrostX


1 Answers

You are looking for something similar to BUILD_CAUSE.Jenkins pipeline doesn't supports cause directly. There is an article link below. You can use the BUILD_CAUSE variable inside the pipeline script to set your variables.

Build Cause Jenkins Pipeline

like image 128
error404 Avatar answered Oct 20 '25 09:10

error404