I have a Jenkins Multibranch project, and I need to set some credentials depending on the Git branch I'm on right now. For example:
# If I'm in master
MY_VARIABLE = credentials("master-credential")
# If I'm in develop
MY_VARIABLE = credentials("develop-credential")
# If I'm in QA
MY_VARIABLE = credentials("qa-credential")
Right now, I've tried to name my variables with a different prefix and setting them up in the following way:
pipeline {
agent any
environment {
MY_VARIABLE = credentials("${env.BRANCH_NAME}-credential")
}
stages {
stage("Start") {
steps {
# use MY_VARIABLE on my steps
}
}
But it doesn't work.
I think I might be able to use different domains for my credentials and then specify the domain when I set them, but I haven't found in the docs how to specify the domains on the Jenkinsfile.
I would really appreciate if someone could help me.
Thanks!