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?