I started to use Jenkins recently. I provides two parameters to collect the dynamic settings and would use them in later stage/steps part (in a bash script). I refer some examples such as
I tried to use parmeter directly or by though environment, multiple combinations, single quote, double quote, etc. But the value gathered from parameters still could NOT been successfully passed to bash command. I believed that this is a very basic requirement but I can not find the proper working example.
Here is my sample code.
pipeline {
agent {
docker {
image ...
args ...
}
}
environment {
USERNAME = ${params.E_USERNANE}
BRANCH = ${params.E_BRANCH}
}
parameters {
string(name: 'E_USERNANE', defaultValue: 'githubuser', description: 'Please input the username')
string(name: 'E_BRANCH', defaultValue: 'dev', description: 'Please input the git branch you want to test')
}
stages {
stage('build') {
steps {
echo "username: ${params.E_USERNANE}"
echo "branch: ${params.E_BRANCH}"
echo E_USERNANE
echo E_BRANCH
sh """
echo ${USERNAME} > /mydata/1.tmp
echo ${BRANCH} >> /mydata/1.tmp
"""
}
}
}
}