在Jenkinsfile中./gradlew由于gitlab推送失败而无法执行发布

时间:2018-06-20 21:37:38

标签: git jenkins kotlin gitlab jenkins-pipeline

我正在使用Gradle 4.1构建一个java / kotlin项目。我正在使用GitLab作为源代码,Jenkins(用于CI和Nexus的多分支管道项目)用作发布和快照的存储库。另外,我正在使用axion-release-plugin。在项目的Jenkinsfile文件中,除其他阶段外,我有一个“发布”阶段,其中运行./gradlew release命令。除'release'以外,其他所有阶段均运行良好(请参阅下面提供的Jenkinsfile中的代码片段的最后一个阶段)。执行此命令时构建失败,错误为:

> Task :release FAILED
Task ':release' is not up-to-date because:
Task has not declared any outputs despite executing actions.
Creating tag: version-0.1.10
Pushing all to remote: origin
Exception occurred during push: 
org.eclipse.jgit.api.errors.TransportException: 
https://GITLAB/MY_REPO.git: not authorized
:release (Thread[Task worker for ':',5,main]) completed. Took 0.821 
secs.

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':release'.
> org.eclipse.jgit.api.errors.TransportException: 
https://GITLAB/MY_REPO.git: not authorized  

node { 

我会遇到此错误,因为我尝试不输入用户名或密码就进行推送。我看过documentation page中的axion-release-plugin,似乎关于如何使用 http:// 链接而不是推送到回购协议的信息很少ssh 。当我按照文档中的说明使用http进行身份验证时,http://axion-release-plugin.readthedocs.io/en/latest/configuration/authorization.html#http-basic-auth-github-tokens并将发布阶段更改为

 stage('release') {

      sh "./gradlew release -Prelease.customUsername= 'MYUSERNAME' -Prelease.customPassword= 'MYPASSWORD' -Prelease.disableChecks"
}

我收到以下错误:

 FAILURE: Build failed with an exception.

 * What went wrong:
 Task 'MYUSERNAME' not found in root project 'MYPROJECT'.

 * Try:
 Run gradlew tasks to get a list of available tasks. Run with --debug 
 option to get more log output. Run with --scan to get full insights.

 * Exception is:
 org.gradle.execution.TaskSelectionException: Task 'MYUSERNAME' not found in 
 root project 'MYPROJECT'.
 at org.gradle.execution.TaskSelector.getSelection(TaskSelector.java:116)

很显然,将密码和用户名直接添加到Jenkinsfile中是行不通的,但是我不知道从哪里获取密码和用户名。 我想知道是否有人知道:

  1. 我可以从哪里加载用于GitLab身份验证的用户名和密码?
  2. 在发布阶段如何在./gradlew release命令中执行此操作?

我的Jenkins文件:

#!/usr/bin/env groovy
node {

env.JAVA_HOME="${tool 'jdk_current'}"

env.GRADLE_HOME="${tool 'gradle_current'}"

env.PATH="${env.JAVA_HOME}/bin:${env.PATH}"

stage('checkout') {
    checkout scm 
}

....

stage('publish') {
    sh "./gradlew publish  --no-daemon --stacktrace"
}

stage('quality') {

   withSonarQubeEnv('FFAWS') {

    sh "./gradlew sonarqube --no-daemon "

    }
}
stage('upload') {
        sh "./gradlew upload --no-daemon --stacktrace "
}

stage('release') {

        sh "./gradlew release -Prelease.disableChecks -Prelease.pushTagsOnly --no-daemon --stacktrace "
}

谢谢!随时询问更多信息。

0 个答案:

没有答案