Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/maven/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Maven Jenkins管道无法使用凭据推送到gerrit_Maven_Jenkins_Jenkins Pipeline_Gerrit_Maven Release Plugin - Fatal编程技术网

Maven Jenkins管道无法使用凭据推送到gerrit

Maven Jenkins管道无法使用凭据推送到gerrit,maven,jenkins,jenkins-pipeline,gerrit,maven-release-plugin,Maven,Jenkins,Jenkins Pipeline,Gerrit,Maven Release Plugin,我是jenkins管道脚本的新手,我正在尝试在管道中使用maven发布插件。但在发布的推进阶段,我遇到了一些问题 这是我的密码: node('linux') { stage('Checkout') { checkout scm } withMaven(maven: 'Maven 3') { stage('Build') { sh "mvn clean verify" junit '**/target/*-reports/TEST-*.xml'

我是jenkins管道脚本的新手,我正在尝试在管道中使用maven发布插件。但在发布的推进阶段,我遇到了一些问题

这是我的密码:

node('linux') {
stage('Checkout') {
    checkout scm
}
 withMaven(maven: 'Maven 3') {

    stage('Build') {
        sh "mvn clean verify"
        junit '**/target/*-reports/TEST-*.xml'
    }

    stage('SonarQube analysis') {
       sh 'mvn sonar:sonar'
    }

     stage('Release') {
        withCredentials([usernamePassword(credentialsId: "jenkins-gerrit", usernameVariable: 'USERNAME', passwordVariable: 'PASSWORD')]) {
            sh 'git config user.email "************************"'
            sh 'git config user.name $USERNAME'
            sh 'mvn -B release:clean release:prepare release:perform -Dusername=$USERNAME -Dpassword=$PASSWORD'
    }
}
}

我得到以下错误:

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-release-plugin:2.4.2:prepare (default-cli) on project aqt-router: Unable to commit files
[ERROR] Provider message:
[ERROR] The git-push command failed.
[ERROR] Command output:
[ERROR] fatal: unable to access 'http://****:****@mygerritserver/myproject/': Could not resolve host: ****; Name or service not known
[ERROR] -> [Help 1]
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException
我尝试直接将个人凭据放入代码中,而不是使用withCredentials:

 sh 'mvn -B release:clean release:prepare release:perform -Dusername=johnDoe -Dpassword=password'
这一次,它似乎找到了gerrit url,但显然,不允许用户推送,因为我们有一个gerrit架构:

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-release-plugin:2.4.2:prepare (default-cli) on project aqt-router: Unable to commit files
[ERROR] Provider message:
[ERROR] The git-push command failed.
[ERROR] Command output:
[ERROR] remote: Branch refs/heads/master:
[ERROR] remote: You are not allowed to perform this operation.
[ERROR] remote: To push into this reference you need 'Push' rights.
[ERROR] remote: User: johnDoe
[ERROR] remote: Please read the documentation and contact an administrator
[ERROR] remote: if you feel the configuration is incorrect
[ERROR] remote:
[ERROR] remote: Processing changes: refs: 1
[ERROR] remote: Processing changes: refs: 1, done
[ERROR] To http://johnDoe:password@mygerritserver/myproject
[ERROR] ! [remote rejected] master -> master (prohibited by Gerrit)
问题是我需要使用jenkins凭证中指定的gerrit用户,因为他有权推送和填充。但我似乎无法通过withCredentials函数使用它

请注意,我无法尝试直接将gerrit用户放入命令行,因为我不知道用户名和密码

谢谢你的帮助

编辑:


感谢@ellak评论,我找到了解决方案:

 def encodedPassword = URLEncoder.encode("$PASSWORD",'UTF-8')
 sh "mvn -B release:clean release:prepare release:perform -Dusername=$USERNAME -Dpassword=$encodedPassword"
实际上,我认为密码包含需要编码的特殊字符。

要在groovy中使用字符串插值,需要使用
而不是

sh "git config user.name $USERNAME"
sh "mvn -B release:clean release:prepare release:perform -Dusername=$USERNAME -Dpassword=$PASSWORD"

感谢@ellak评论,我找到了解决方案:

 def encodedPassword = URLEncoder.encode("$PASSWORD",'UTF-8')
 sh "mvn -B release:clean release:prepare release:perform -Dusername=$USERNAME -Dpassword=$encodedPassword"

事实上,我认为密码中包含需要编码的特殊字符。

谢谢,我尝试了”,但仍然出现相同的错误。密码是否包含一些特殊字符?如果您这样做有帮助吗?
-Dpassword='$PASSWORD'
谢谢您,我找到了解决方案很高兴听到!