Hasan Hafiz Pasha
Hasan Hafiz Pasha

Reputation: 1432

Jenkins Pipeline - conditional execution with branch and 1 other parameter (manual)

We are deploying our application using Jenkins pipeline like this -

pipeline {
  agent any
  stages {
    stage('Build For Production') {
        when { branch 'development' }
        steps {
             sh './bin/build.sh'
        }
    }
    stage('Build For Production') {
        when { branch 'master' }
        steps {
             sh './bin/copy_needed_auth.sh'
             sh './bin/build.sh'
        }
    }
  }
}

When a developer pushes code on bitbucket, The application is deployed automatically. Using branch, we set our deployment strategy.

when { branch 'master' }

But we need to set a manual chacking for deploying on production (master branch) like - when a developer will merge code in the master branch, he will also set some tag or something like that so that Jenkins pipeline will check branch + other manual logic to deploy in production.

we are doing like this -

when { 
    branch 'master' 
    tag: 'release-*'
}

But it's not working. Is there any other strategy to do that?

Upvotes: 0

Views: 515

Answers (1)

Dmitriy Tarasevich
Dmitriy Tarasevich

Reputation: 1242

Use following code to use several when conditions:

when { 
  allOf { 
    branch 'master'; 
    tag "release-*"
  }
}

Related docs you can find here

Upvotes: 1

Related Questions