Jenkins 管道 - mvn 命令未正确读取 withCredentials 变量
Jenkins pipeline - mvn command doesn't read withCredentials variables properly
我正在尝试为 Maven 使用 jgitflow 插件,运行 通过 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"
}
上面的设置不起作用,但如果我显式传递用户名和密码而不是通过变量传递,一切都很好。我用错了吗?
在某些情况下,管道脚本生成的输出很棘手,无法按原样使用。使用以下代码访问凭据:
withCredentials([[$class: 'UsernamePasswordMultiBinding', credentialsId: '<CREDENTIAL_ID>', usernameVariable: 'USERNAME', passwordVariable: 'PASSWORD']])
而不是生成的代码。
我正在尝试为 Maven 使用 jgitflow 插件,运行 通过 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"
}
上面的设置不起作用,但如果我显式传递用户名和密码而不是通过变量传递,一切都很好。我用错了吗?
在某些情况下,管道脚本生成的输出很棘手,无法按原样使用。使用以下代码访问凭据:
withCredentials([[$class: 'UsernamePasswordMultiBinding', credentialsId: '<CREDENTIAL_ID>', usernameVariable: 'USERNAME', passwordVariable: 'PASSWORD']])
而不是生成的代码。