Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

S3 Copy artifacts with Jenkins pipeline

I'm trying to use the S3 plugin in a Jenkins 2.0 pipeline with a Jenkinsfile. Unfortunately, the pipeline syntax helper does not seem to be very complete.

I got the following code :

step([$class: 'S3CopyArtifact', buildSelector: [$class: 'StatusBuildSelector', stable: true], excludeFilter: '', filter: 'deploy/*.zip', flatten: false, optional: false, projectName: 'my/project/with/folders', target: '/my/directory/'])

Off course this is not sufficient, as credentials and bucket are missing. Additionnaly, this plugin does not seem to behave correctly with the Folders plugin.

Does anyone have hints on this ?

like image 724
trey Avatar asked Dec 06 '22 16:12

trey


2 Answers

I agree with your original statement in that the script generation is oh so sad. It does not give enough to go on, even when you have S3BucketPublisher selected. See my snippet below. It assumes you've created a profile already in the system configuration.

stage("publish to s3") {
    step([
        $class: 'S3BucketPublisher',
        entries: [[
            sourceFile: 'mybinaryFile',
            bucket: 'GoBinaries',
            selectedRegion: 'eu-west-1',
            noUploadOnFailure: true,
            managedArtifacts: true,
            flatten: true,
            showDirectlyInBrowser: true,
            keepForever: true,
        ]],
        profileName: 'myprofile',
        dontWaitForConcurrentBuildCompletion: false, 
    ])
}
like image 184
djsd123 Avatar answered Jan 01 '23 02:01

djsd123


For a simpler use case this is now supported in Pipeline AWS Plugin like this: s3Upload(file:'someFolder', bucket:'my-bucket', path:'/path/to/targetFolder/')

djsd123's example works perfectly for more advanced use cases. If you also want to add metadata tags to your objects you can add a userMetaData array:

    profileName: 'myprofile',
    dontWaitForConcurrentBuildCompletion: false, 
    userMetadata: [[ key: 'git_branch', value: "${env.BRANCH_NAME}"],
                   [ key: 'build_number', value: "${env.BUILD_NUMBER}"]
    ],
like image 39
antweiss Avatar answered Jan 01 '23 02:01

antweiss