I'm trying to send email notifications to specific user whose branch is currently checked out in the Jenkins build process. For accomplishing this, I have used naming conventions in the environment variables.
E.g.
master_MAIL = [email protected]
ABC_MAIL = [email protected]
Where MASTER
and ABC
are actual branch names.
env.GIT_LOCAL_BRANCH
gives me with the current branch name being checked out.
Based on the current branch name, I have to pick the correct environment variable, and store its value (mail ID) to another environment variable.
pipeline {
agent any
environment {
CURRENT_MAIL = "\$${env.GIT_LOCAL_BRANCH}_MAIL"
// Here I am trying to pick the specific mail id of the branch being
// check out and store it to new environment variable named
// "CURRENT_MAIL".
// But This gives only the value "$master_MAIL" but not the value
// stored in master_MAIL environment variable.
}
stages {
}
post {
always {
mail (
from: ""
to: "$CURRENT_MAIL"
// Here I have to use that environment variable to send email to
// that specific user.
subject: "")
}
}
The expected result is: CURRENT_MAIL
environment variable should have the value contained in the {Branchname}_MAIL
environment variable.
E.g. Consider I have these two environment variables set in my configuration:
master_MAIL = [email protected]
ABC_MAIL = [email protected]
Then, if the current branch being checked out is master
branch, then the environment variable CURRENT_MAIL
should have the value [email protected]
.