【发布时间】:2018-10-07 00:46:06
【问题描述】:
我正在尝试将 jgitflow 插件用于 maven 并通过 Jenkins 管道运行发布。
插件配置:
<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 的凭据时。
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"
}
上面的设置不起作用,但如果我明确地传递用户名和密码而不是变量,一切都很好。是不是我用错了?
【问题讨论】:
-
您是如何为凭据生成管道脚本的?
-
使用 Jenkins 的“管道语法”页面。我尝试调用
echo "$USERNAME",它给了我一个掩码形式的用户名,所以我认为语法是正确的。 -
您可以尝试按照以下语法添加:
withCredentials([[$class: 'UsernamePasswordMultiBinding', credentialsId: '<CREDENTIAL_ID>', usernameVariable: 'USERNAME', passwordVariable: 'PASSWORD']]) -
它有效,谢谢。我必须阅读有关凭据绑定的更多信息。
-
太棒了!我会更新它作为答案。帮助我批准,以便其他人也可以受益
标签: jenkins jenkins-pipeline jgitflow-maven-plugin