【问题标题】:How to pass username password to Gradle to upload artifacts to Nexus from a Jenkins pipeline如何将用户名密码传递给 Gradle 以将工件从 Jenkins 管道上传到 Nexus
【发布时间】:2018-01-09 15:41:49
【问题描述】:

我需要从 Jenkins 声明式管道将工件上传到 Nexus。有一个 Nexus plugin 我不能使用,因为它不允许发布 SNAPSHOT。因此我必须通过 Gradle 上传任务直接上传它们。问题是我从 Nexus 收到 401 错误代码,并且似乎没有将 nexus 用户和密码从管道传递到 ./gradlew upload 任务。

这是我当前的配置:

管道

withCredentials([usernamePassword(credentialsId: 'asdf23432-fe69-1234-2222-ffa65yteec2c', passwordVariable: 'NEXUS_PASSWORD', usernameVariable: 'NEXUS_USER')]) {
    sh "./gradlew upload --debug"
}

Gradle:在下一节中,我尝试从 withCredentials 步骤访问 NEXUS_USER 和 NEXUS_PASSWORD 变量。

ext{
    nexusUser = System.properties['NEXUS_USER']
    nexusPassword = System.properties['NEXUS_PASSWORD']
}

uploadArchives {
    repositories {
        mavenDeployer {
            snapshotRepository(url: 'http://somerepo'){
                authentication(userName: nexusUser, password: nexusPassword)
            }
        }
    }
}

【问题讨论】:

    标签: jenkins gradle jenkins-pipeline nexus


    【解决方案1】:

    您可以使用以下方法将变量作为系统属性传递:

    withCredentials([usernamePassword(credentialsId: 'asdf23432-fe69-1234-2222-ffa65yteec2c', passwordVariable: 'NEXUS_PASSWORD', usernameVariable: 'NEXUS_USER')]) {
        sh "./gradlew -DNEXUS_PASSWORD=$NEXUS_PASSWORD -DNEXUS_USER=$NEXUS_USER upload --debug"
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-07-01
      • 2020-02-15
      • 1970-01-01
      • 2022-11-19
      • 2014-12-25
      • 1970-01-01
      • 1970-01-01
      • 2011-06-19
      相关资源
      最近更新 更多