gpt4 book ai didi

jenkins - 如何在 jenkins 管道中连接两个 env 变量,中间有一个斜线?

转载 作者:行者123 更新时间:2023-12-01 04:48:29 27 4
gpt4 key购买 nike

我有一个脚本可以将生成的 RPM 发送到 Nexus OSS 管理器。 Jenkins的阶段是:

stage ('nexus deploy') {
env.REPONAME = "snapshots"
sh '''
mvn deploy:deploy-file -Durl="${env.NEXUS_URL}/$env.REPONAME"
'''
}

我已经设置了环境变量 env.NEXUS_URL但是用两个变量并排调用它,中间有一个斜线,不知何故没有检测到变量,并且构建失败并出现错误。
-Durl="${env.NEXUS_URL}/$REPONAME": bad substitution

最佳答案

你在混淆 groovy语法和 shell 中的语法.
您可以使用 env.VARgroovy你可以使用 ${VAR}之间sh '..' :

pipeline {
agent any

options {
buildDiscarder(logRotator(numToKeepStr: '3'))
}

environment {
NEXUS_URL = 'https://mynexus.com'
REPONAME = 'myrepo'
}

stages {
stage('test') {
steps {
echo "print env vars in groovy"
echo "my nexus is " + env.NEXUS_URL + " any my repo name is " + env.REPONAME
sh 'echo "env vars in sh"'
sh 'echo "nexus is ${NEXUS_URL} and my repo name is ${REPONAME}"'
}
}
}
}

输出:
[Pipeline] echo
print env vars in groovy
[Pipeline] echo
my nexus is https://mynexus.com any my repo name is myrepo
[Pipeline] sh
[test] Running shell script
+ echo 'env vars in sh'
env vars in sh
[Pipeline] sh
[test] Running shell script
+ echo 'nexus is https://mynexus.com and my repo name is myrepo'
nexus is https://mynexus.com and my repo name is myrepo

在您的情况下,您需要:
mvn deploy:deploy-file -Durl=${NEXUS_URL}/${REPONAME}

关于jenkins - 如何在 jenkins 管道中连接两个 env 变量,中间有一个斜线?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47594084/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com