GitLab CI secret variables for Gradle publish

后端 未结 3 1866
臣服心动
臣服心动 2021-02-20 14:39

How to setup Gradle publish task user credentials with GitLab CI secret variables? I am using gradle maven publish plugin, and here is snippet from build.gradle

         


        
3条回答
  •  青春惊慌失措
    2021-02-20 15:22

    Here is how I resolved it (unfortunately the official GitLab doco is very focused on Maven... :(

    apply plugin: 'java'
    apply plugin: 'maven-publish'
    
    compileJava.options.encoding = 'UTF-8'
    group = 'com.example'
    version = '1.0.9'
    
    
    task zipSource(type: Zip) {
        from file('files/test.zip')
        archiveClassifier = 'testZip'
    }
    
    publishing {
        repositories {
            maven {
                name 'GitLab' 
                url 'https://gitlab.my-company.com/api/v4/projects/2302/packages/maven'
                credentials(HttpHeaderCredentials) {
                    name = "Job-Token"
                    value = System.getenv("CI_JOB_TOKEN")
                }
                authentication {
                    header(HttpHeaderAuthentication)
                }
            }
       }
       publications {
            mavenJava(MavenPublication) {
                artifactId = 'project1-sample'
                //deploy jar vom Java
                from components.java
                //deploy arbitrary Zip file
                artifact zipSource
            }
        }
    }
    

提交回复
热议问题