Hi,
In Jenkins multibranch pipeline, this works.
OPTION 1:
stage(‘Post to Slack’) {
environment {
SLACK_WEBHOOK = credentials(‘mycreds_testing’)
}
steps {
sh ‘’'#!/bin/bash
curl $SLACK_WEBHOOK
And this does not:
OPTION 2:
stage(‘Post to Slack’) {
environment {
SLACK_WEBHOOK = “${env.GIT_URL =~ “org1” || env.GIT_URL =~ “org2” ? credentials(‘mycreds_testing’) : credentials(‘mycreds’)}”
}
steps {
sh ‘’'#!/bin/bash
curl $SLACK_WEBHOOK
When curl tries to reach the webhook, it says “Could not resolve host: credentials(=mycreds_testing)”
It’s as if option1 successfully resolves the credential information and places it into the variable SLACK_WEBHOOK. However, option 2 keeps the creds secret, and fails to decipher them.
I have already implemented a work-around: look up ALL creds in the ‘environment’, separately. As multiple variables. Move the ternary logic into the bash script. Choose which variable to use there. So, this is not critical to solve. Only a curiosity. And to have results in the community about: “ternary credentials environment”.
In any case, if you are reading this and understand Jenkins pipeline syntax: why isn’t option 2 correct?