2

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?

Stepan
  • 131
  • 1
  • 1
  • 4

2 Answers2

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.

jayhendren
  • 3,022
  • 8
  • 16
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

Stepan
  • 131
  • 1
  • 1
  • 4