如何在jenkins管道中用斜线连接两个env变量?

如何在jenkins管道中用斜线连接两个env变量?,jenkins,environment-variables,concatenation,jenkins-pipeline,Jenkins,Environment Variables,Concatenation,Jenkins Pipeline,我有一个脚本,可以将生成的RPM发送到NexusOSS管理器。詹金斯的舞台是: stage('nexus deploy'){ env.REPONAME=“快照” “嘘” mvn部署:部署文件-Durl=“${env.NEXUS_URL}/$env.REPONAME” ''' } 我已经设置了env变量env.NEXUS_URL,但是用两个变量并排调用它时,中间有一个斜杠,不知何故没有检测到这些变量,并且构建失败并出现错误 -Durl="${env.NEXUS_URL}/$REPONAME":

我有一个脚本,可以将生成的RPM发送到NexusOSS管理器。詹金斯的舞台是:

stage('nexus deploy'){
env.REPONAME=“快照”
“嘘”
mvn部署:部署文件-Durl=“${env.NEXUS_URL}/$env.REPONAME”
'''
}
我已经设置了env变量
env.NEXUS_URL
,但是用两个变量并排调用它时,中间有一个斜杠,不知何故没有检测到这些变量,并且构建失败并出现错误

-Durl="${env.NEXUS_URL}/$REPONAME": bad substitution

您混淆了
groovy
语法和
shell
中的语法。 您可以在
groovy
中使用
env.VAR
,也可以在
sh'..
之间使用
${VAR}

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}

您的
mvn部署:部署文件-Durl=“${env.NEXUS_URL}/$env.REPONAME”
正在shell上执行,并且
env.NEXUS_URL
env.REPONAME
都是无效的shell替换。