How do I pass Jenkins credentials to gradle?

前端 未结 1 1160
醉话见心
醉话见心 2021-01-21 03:20

I\'m using the jib Gradle plugin to create a docker image and push it to the Azure Container Registry. I\'ve added username/password credentials to Jenkins so far and need to pa

1条回答
  •  礼貌的吻别
    2021-01-21 03:43

    I had a typo in the username. Passing Jenkins credentials as environment variables works as expected. Here's my code: build.gradle (jib configuration):

    jib {
        to {
            image = "myacr.azurecr.io/" + project.name
            tags = ["latest"]
            auth {
                // retrieve from Jenkins
                username "${System.env.ACR_CREDENTIALS_USR}"
                password "${System.env.ACR_CREDENTIALS_PSW}"
            }
        }
        container {
            jvmFlags = ["-Xms512M",  "-Xmx1G"]
            ports = ["5000/tcp", "8080/tcp"]
        }    
    }
    

    Jenkinsfile:

    pipeline {
    ...
        environment {
            ACR_CREDENTIALS = credentials('myproject-acr') 
        }
    
        stages {
            ...
            stage('Push Docker Image to Registry') {
                steps {
                    sh "./gradlew jib"
                }
            }
    ...
    

    0 讨论(0)
提交回复
热议问题