Home > OS >  How to pass a variable in Jenkins Credentials Helper Function
How to pass a variable in Jenkins Credentials Helper Function

Time:06-21

 environment {
    BRANCH_NAME = "${env.BRANCH_NAME}"
    DEPLOYMENT_MACHINE = credentials('auto-deployment')
}

How to pass Variable to credentials Function like

environment {
    BRANCH_NAME = "${env.BRANCH_NAME}"
    DEPLOYMENT_MACHINE = credentials("${BRANCH_NAME}")
}

CodePudding user response:

"${exp}" is Groovy String interpolation, it is an alternative to "" exp "".

thus you can simply do

def deploymentBranchCred = credential(env.BRANCH_NAME)

CodePudding user response:

 environment {    
    DEPLOYMENT_MACHINE = credentials("${env.BRANCH_NAME}")
    BRANCH = "${env.BRANCH_NAME}"
}

It's Working Fine.! issue with BRANCH_NAME as declared again in the environment.

  • Related