Create a Jenkins pipeline to pull the artifact from a Nexus repository & upload it to an AWS S3 bucket

Jenkins logo taken from https://jenkins.io/

Introduction.

Requirements.

  1. AWS free tier (if you aren’t an existing AWS customer).
  2. AWS Access Key ID & Secret Access Key — It should have write permissions on the pre-existing S3 bucket.
  3. Jenkins Pipeline: AWS Steps plugin.
  4. Jenkins Credentials plugin.
  5. Nexus repository (raw type) — You can also use a different type of Nexus repository. I created a repository with the name: s3-repo.
  6. A file already uploaded to the above-mentioned Nexus repository — The pipeline will retrieve this file & upload it to the S3 bucket. It can be any file, but I chose a PNG image file. Feel free to upload any type of file.

Steps to follow.

  • Create a free AWS account, if don’t already have one. You can use the free tier for this exercise.
  • Create an S3 bucket & make it public.
  • Create a new job in Jenkins of type Pipeline.
  • Configure this job & add below pipeline script. You have options to either create the credentials with the same IDs or replace the IDs with your values in this script.
node {
stage('Pull the file off Nexus') {
withCredentials([usernameColonPassword(credentialsId: 'nexus-admin-user', variable: 'NEXUS_CREDENTIALS')]) {
sh script: 'curl -u ${NEXUS_CREDENTIALS} -o your_file.png "http://localhost:8083/repository/s3-repo/photos/your_file.png"'
}
}
stage('Upload file(s) to S3') {
withAWS(region:'ap-south-1',credentials:'aws_root') {
s3Upload(bucket:"your-bucket-name", file:'your_file.png');
}
}
}

Explanation of this script.

Configure Jenkins to add 2 credentials — 1 for Nexus & 1 for AWS.

Bind the Nexus credentials to a variable.

Run the build.

--

--

--

Principal Engineer @Paytm, Music/Book/Photography/Fitness lover & Blogger

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

One programmer interview #1 Non Technical Part.

TRYHACKME CTF — Library

Exception Handling

Intricacies of Python

Create a simple custom image

Jupyter Notebook in Anaconda new Environment

Wreck-It Alex | DBFF #57

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Shashank Srivastava

Shashank Srivastava

Principal Engineer @Paytm, Music/Book/Photography/Fitness lover & Blogger

More from Medium

Build Docker container images with AWS CodeBuild

Packer Building AWS AMI Images

[AWS security] How to secure API calls using CloudTrail

Automate the build of your application (on Jenkins)