I have a custom Nexus for project related utility jars. I have a Jenkins to build these jars.
I want to use gradle in the project and a Jenkinsfile to define the pipeline. As the last stage, I want the build job to deploy the artifact to my Nexus.
Since I don't want the credentials for the Nexus in my source repository (and therefor neither in the gradle script nor in the Jenkinsfile), I set up a credentials entry in the Jenkins Credentials plugin, containing user and password for the Nexus.
How do I refer to these credentials from within the Jenkinsfile such that I can use them to deploy to the Nexus?
Currently, my deploy stage looks like this:
stage('Publish') {
sh "gradle upload"
}
Can I use gradle for this purpose at all? I know I can use it locally, but it would be ok for me to use a different command from within the Jenkinsfile.
In gradle, I use this to define the task:
def nexusUser = "$System.env.NEXUS_USER"
def nexusPass = "$System.env.NEXUS_PASS"
uploadArchives {
repositories {
mavenDeployer {
repository(url: "http://nexus.example.com/repository/maven-releases/") {
authentication(userName: nexusUser, password: nexusPass)
}
}
}
}
(I set the user and password as environment variables locally. That's not an option on the Jenkins, of course.)
Global Credentials provided by Jenkins
? Could you formulated that as an answer? Thank you for the quick response! – inedible{}
– Vitalii Vitrenko