最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

jenkins - Accessing properties from build.gradle coming as null - Stack Overflow

programmeradmin4浏览0评论

We are trying to pull the maven repository with credentials from build.gradle file, where as credentials are stored in Jenkins. These credentials are required to pull from Jenkinfile to Makefile where gradle build is called and then need to pass to build.gradle. The repository pull was then used in build.gradle file. Currently we are not able to access the credentials from gradle which is passed from Jenkinfile. Here is how i saved my credentials:

environment {
                ARCHIVA=credentials('ARCHIVA')
            }
            steps {
                echo 'Build + Test'
                //sh 'make build'
                // Retrieve Archiva credentials from Jenkins
                    withCredentials([usernamePassword(credentialsId: 'ARCHIVA',
                                                       usernameVariable: 'ARCHIVA_USR',
                                                       passwordVariable: 'ARCHIVA_PSW')]) {
                         // Fetch the username and password from Jenkins credentials
                        def archivaUsername = ARCHIVA_USR
                        def archivaPassword = ARCHIVA_PSW
                        // Pass Archiva credentials to Makefile
                        sh """
                            make build ARCHIVA_USR=${archivaUsername} `enter code here`ARCHIVA_PSW=${archivaPassword}
                        """
                    }
            }

In Makefile i have retrieved it and forwarded to build.gradle:

ARCHIVA_USR = $(ARCHIVA_USR)
ARCHIVA_PSW = $(ARCHIVA_PSW)
build:
bash -c "cd /logging && ./gradlew --no-daemon -g /opt/app/.gradle clean build -x test buildDocker -PVERSION_NUM=${VERSION_NUM} -PmavenVersion=1 -ParchivaUsr=${ARCHIVA_USR} -ParchivaPsw=${ARCHIVA_PSW}"

But when tried to retrieve in gradle file it is coming as null. Tried below way to access it.

dockerUsername = project.hasProperty('ParchivaUsr') ? project.ParchivaUsr: ''
archivaUsr = System.getenv('ARCHIVA_USR') ? System.getenv('ARCHIVA_USR') : ''

Anything wrong in this flow?

发布评论

评论列表(0)

  1. 暂无评论