2

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?

FrostX
  • 93
  • 1
  • 10
  • 1
    This question is actually how to get the BUILD_USER. Already answered here https://stackoverflow.com/questions/49553378/jenkins-java-get-user-who-started-the-build – hakamairi Feb 19 '19 at 07:03

1 Answers1

2

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

error404
  • 2,684
  • 2
  • 13
  • 21