Answers: <p>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.</p>
  <p><code>$PROD = xyz_prod</code></p>
  <p>Then,</p>
  <p><code> when {  branch 'master'  tag: $PROD }</code></p>
  <p>Not sure why your approach failed, but building tags on a script using variables could do the trick.</p>
  
Answers: CC BY-SA 4.0
Answers: 2021-08-09T01:44:54.840Z
Answers: 2021-08-09T01:44:54.840Z
Answers: the_piper
Body: <p>We are deploying our application using Jenkins pipeline like this -</p>
  <pre><code>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'
          }
      }
    }
  }
  </code></pre>
  <p>When a developer pushes code on bitbucket, The application is deployed automatically. Using branch, we set our deployment strategy.</p>
  <pre><code>when { branch 'master' }
  </code></pre>
  <p>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.</p>
  <p>we are doing like this -</p>
  <pre><code>when { 
      branch 'master' 
      tag: 'release-*'
  }
  </code></pre>
  <p>But it's not working. Is there any other strategy to do that?</p>
  
Tags: <jenkins><jenkins-pipeline>
Title: Jenkins Pipeline - conditional execution with branch and 1 other parameter (manual)
UserDisplayName: Hasan Hafiz Pasha
ThreadText: # Jenkins Pipeline - conditional execution with branch and 1 other parameter (manual)
  
  (Asked by: username_0 on 2021-08-08)
  
  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?
  
  **Tags:** jenkins, jenkins-pipeline
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2021-08-09. Score: 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.
  
  
  ---
  
  