我有一个Jenkinsfile,我需要通过连接变量和字符串来准备zip文件路径。我尝试了下面的片段,但它分裂成多行,像这样:
13:14:02 Zip File Path: /apps/external/5/jenkins-node-home/workspace/APPL004316/APIN004621
13:14:02 /my_project
13:14:02 -0.1.29
13:14:02 -SNAPSHOT.zip
预期输出为:/apps/external/5/jenkins-node-home/workspace/APPL004316/APIN004621/my_project-0.1.29-SNAPSHOT.zip
嗅探器:
stage('Zip') {
steps {
script {
env.VERSION = sh script: 'grep -m 1 version_number ${WORKSPACE}/ComponentInfo.toml | tr -s \' \' | tr -d \'"\' | tr -d "\'" | cut -d\' \' -f3', returnStdout: true
echo "Version: ${env.VERSION}"
env.PROJECT = sh script: 'echo "${WORKSPACE}"|rev|cut -d\'/\' -f1|cut -d\'@\' -f2|rev', returnStdout: true
echo "Project: ${env.PROJECT}"
env.BASEPATH = sh script: 'echo ${WORKSPACE%/*}' , returnStdout: true
env.ZIP_FILEPATH = "${env.BASEPATH}/${env.PROJECT}-${env.VERSION}-SNAPSHOT.zip"
echo "Zip File Path: ${env.ZIP_FILEPATH}"
}
}
}
我也试过使用**"+"**,但得到的结果是一样的:
env.ZIP_FILEPATH = env.BASEPATH+"/"+env.PROJECT+"-"+env.VERSION+"-SNAPSHOT.zip"
1条答案
按热度按时间jgzswidk1#
正如@NoamHelmer所说,添加
.trim()
起作用了。env.ZIP_FILEPATH = "${env.BASEPATH.trim()}/${env.PROJECT.trim()}-${env.VERSION.trim()}-SNAPSHOT.zip"
谢谢诺姆