1

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?

1

If I got it right, you could try to tag by using environment variables. Maybe something defined in the environment {} directive within the stage. E. g.

$PROD = xyz_prod

Then,

when { branch 'master' tag: $PROD }

Not sure why your approach failed, but building tags on a script using variables could do the trick.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.