Jenkinsfile with user input with variable in select

I want to use the new Jenkins file for a new job.

I have a jenkinsfile that I have in my solo repository:

  • I get branches from another gitlab repository on git ls-remote in bash. And I store them in variables: branch1, branch2, brach3 ....
  • Then I want to use these variables in user input options

    script {                
      env.BRANCHDEPLOY = input message: 'User input required',
      ok: 'Deploy!',
      parameters: [choice(name: 'Branch to deploy', choices: '${branch1}\n${branch2}\n${branch3}', description: 'What branch you wont deploy?')]
    }
    echo "${env.BRANCHDEPLOY}"
    
  • Then I will use ${env.BRANCHDEPLOY}for git to deploy the selected branch.

The problem is that I can not get to work with variables in the choice of the user.

I just need to let the user select the branch that he wants to deploy from another gitlab repository.

+2
source share
2 answers

, , script. .

"${branch1}\n${branch2}\n${branch3}"

:

pipeline {
agent any

environment{
    branch1 = 'stack'
    branch2 = 'over'
    branch3 = 'flow'
}

stages {
    stage('Stage-One') {
        steps {
            script {                
                env.BRANCHDEPLOY = input message: 'User input required',
                ok: 'Deploy!',
                parameters: [choice(name: 'Branch to deploy', choices: "${branch1}\n${branch2}\n${branch3}", description: 'What branch you wont deploy?')]
            }
        }
    }
    stage('Stage-Two'){
        steps{
            sh "echo ${BRANCHDEPLOY}"
        }
    }
}

}

+2

- , var.

parameters {
    string(branchName: 'feature_x')
}
scm {
    checkout(
      branches: [[name: '*/$branchName']], 
....

 }
0

Source: https://habr.com/ru/post/1675174/


All Articles