Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jenkins pipeline: how to upload artifacts with s3 plugin

Im trying to upload artifacts to an s3 bucket after a successful build, but i cant find any working example to be implemented into a stage/node block.

any idea ( s3 plugin installed, jenkins v2.32 )?

node {
  sh 'echo ""> 1.jar'
  archiveArtifacts artifacts: '1.jar', fingerprint: true
  // upload to s3 bucket ???
}    
like image 205
chenchuk Avatar asked Feb 06 '17 18:02

chenchuk


People also ask

How do you publish artifacts in Jenkins pipeline?

Select your build pipeline, and then select Configure to edit your build definition. Select Build, and then select Add build step to add a new task. Select Save, and then queue your build. Your NuGet package should be published to your Azure Artifacts feed.

How do I add an artifact to Jenkins?

How to Create an Artifact. In Jenkins, an artifact is created in either Freestyle projects or Pipeline projects. In Freestyle, add the “Archive the artifacts” post-build step. In Pipeline, use the archiveArtifacts step.


3 Answers

Detailed steps:

  1. Install Pipeline AWS Plugin. Go to Manage Jenkins -> Manage Plugins -> Available tab -> Filter by 'Pipeline AWS'. Install the plugin.

  2. Add Credentials as per your environment. Example here:

    Jenkins > Credentials > System > Global credentials (unrestricted) -> Add

    Kind = AWS Credentials and add your AWS credentials

    Note the ID

  3. Then in your Pipeline project (Similar to the code I use)

    node {
    
        stage('Upload') {
    
            dir('path/to/your/project/workspace'){
    
                pwd(); //Log current directory
    
                withAWS(region:'yourS3Region',credentials:'yourIDfromStep2') {
    
                     def identity=awsIdentity();//Log AWS credentials
    
                    // Upload files from working directory 'dist' in your project workspace
                    s3Upload(bucket:"yourBucketName", workingDir:'dist', includePathPattern:'**/*');
                }
    
            };
        }
    }
    
like image 79
aCiD Avatar answered Oct 16 '22 20:10

aCiD


Looking at the Pipeline Steps documentation on the Jenkins website, it shows that the Pipeline AWS Plugin provides an s3Upload step.

like image 20
Christopher Orr Avatar answered Oct 16 '22 18:10

Christopher Orr


Try this:

s3Upload(file:'file.txt', bucket:'my-bucket', path:'path/to/target/file.txt')

I think it is easier to show the direct plugin documentation URL. You can find the plugin documentation here.

As you are looking for a way to upload files to S3, here are some examples.

like image 42
ErikWe Avatar answered Oct 16 '22 20:10

ErikWe