1

I use ssh username and private key auth to download sources from Git, build the artifact and deploy it to my nginx server. Now I need to download an artifact as a zip file to Jenkins agent, prepare it and deploy to my nginx server. I can only access Nexus using username/password pair.

Is there a way to run scp mynexus.com/my_artifact.zip ~/my_artifact.zip and pass username with password from Jenkins credentials?

1

There are a few ways to do this, but by far the easiest is to put your credentials (either username/password or ssh keypair) into the Jenkins built-in credentials store and then use the sshagent step in your Pipeline script:

sshagent(credentials: ['my-credentials']) {
  sh('scp mynexus.com/my_artifact.zip ~/my_artifact.zip')
}

You may need to install the SSH Agent plugin to be able to use this step; I'm not sure if it's part of the default set of Pipeline plugins or not.

1

Create String parameter artifactID, Password parameter NexusUser with username and Password parameter NexusPassword with nexus password.

curl -v -u $NexusUser:$NexusPassword -o ~/tmp_dl/distr.zip https://my_nexus_url.com/nexus/content/repositories/${artifactID}/distrib.zip

1
  • 1
    In all likelihood @this will end up exposing the username/password bin cleartext in the logs. So you should also use the Mak Paawords plugin. Use credentials approach instead. – Ian W May 15 '20 at 2:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.