Answer the question
In order to leave comments, you need to log in
How to correctly assign a value to a variable with a path and pass it to sh?
Hello.
During the development of the script file for jenkins, it was necessary to assign the path value to the variable in order to further pass it to sh
prepared the script
#!groovy
node('superhost01'){
String HOSTNAME="host01"
String USERNAME="tech_user"
env.PATH="/data/jdbc_connector"
stage('Prepare') {
checkout scm
}
stage('Deploy') {
sh """
scp -r config.yaml ${USERNAME}@${HOSTNAME}:$PATH
"""
}
}
env.PATH="/data/jdbc_connector"
Answer the question
In order to leave comments, you need to log in
correct option is to use withEnv
#!groovy
node('superhost01'){
String HOSTNAME="host01"
String USERNAME="tech_user"
withEnv(['PATH=/data/jdbc_connector']) {
stage('Prepare') {
checkout scm
}
stage('Deploy') {
sh """
scp -r config.yaml ${USERNAME}@${HOSTNAME}:$PATH
"""
}
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question