首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Jenkins管线- mvn命令不能正确读取withCredentials变量

Jenkins管线- mvn命令不能正确读取withCredentials变量
EN

Stack Overflow用户
提问于 2018-04-26 10:41:52
回答 1查看 1.7K关注 0票数 2

我正在尝试为maven使用jgitflow插件,并通过Jenkins管道运行一个版本。

插件配置:

代码语言:javascript
复制
<plugin>
     <groupId>external.atlassian.jgitflow</groupId>
     <artifactId>jgitflow-maven-plugin</artifactId>
     <version>1.0-m5.1</version>
     <configuration>
        <username>${git.user}</username>
        <password>${git.password}</password>
        <enableSshAgent>true</enableSshAgent>
        <autoVersionSubmodules>true</autoVersionSubmodules>
        <noDeploy>true</noDeploy>
        <releaseBranchVersionSuffix>-RELEASE</releaseBranchVersionSuffix>
     </configuration>
</plugin>

问题是当我传递jgitflow的凭据时。

代码语言:javascript
复制
withCredentials([usernamePassword(credentialsId: 'my_credentials_id', passwordVariable: 'USERNAME', usernameVariable: 'PASSWORD')]) {
    sh "git checkout develop"
    sh "mvn -f jgitflow:release-start -B -U -DskipTests -DnoDeploy=true -DpushReleases=false -Dgit.user=$USERNAME -Dgit.password=$PASSWORD"
    sh "mvn -f jgitflow:release-finish -B -U -Dmaven.javadoc.skip=true -DskipTests -DnoDeploy=true -DpushReleases=true -Dgit.user=$USERNAME -Dgit.password=$PASSWORD"
 }

上面的设置不起作用,但是如果我显式地传递用户名和密码而不是变量,一切都很好。我用错了吗?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-04-26 11:13:38

在某些情况下,管道脚本生成的输出很棘手,不能按原样使用。使用以下代码访问凭据:

代码语言:javascript
复制
withCredentials([[$class: 'UsernamePasswordMultiBinding', credentialsId: '<CREDENTIAL_ID>', usernameVariable: 'USERNAME', passwordVariable: 'PASSWORD']])

而不是生成的代码。

票数 4
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/50040933

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档