Home > other >  Groovy compilation errors with S3Publisher plugin in Jenkinsfile Pipeline
Groovy compilation errors with S3Publisher plugin in Jenkinsfile Pipeline

Time:05-09

A very novice Jenkins question but I have unable to find any solutions and probably due to my limited understanding of Jenkins, maybe not able to make sense of the documentation available. I am working with the S3publisher plugin in Jenkins and have correctly configured the aws credentials for this plugin. However, I am unable to write a Jenkinsfile to upload a file using this plugin. I am pasting a truncated pipeline below:

pipeline {
    agent any
    stages {
       stage("publish to s3") {
            steps {
                    //$class: 'S3BucketPublisher',
                    $class: 'S3Upload',
                    profileName: ‘myawsprofile’,
                    entries: [[
                        bucket: ‘mybucket’, 
                        excludedFile: '', 
                        flatten: false, 
                        gzipFiles: false, 
                        keepForever: false, 
                        managedArtifacts: false, 
                        noUploadOnFailure: false, 
                        selectedRegion: 'us-iso-east-1',
                        howDirectlyInBrowser: false, 
                        sourceFile: ‘myfile’, 
                        storageClass: 'STANDARD', 
                        uploadFromSlave: false, 
                        useServerSideEncryption: false]]
                }
            }
        }
    }
 }

I have done various modifications and I keep running into org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed error while running the Jenkins pipeline. The latest error that I see is:

org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
WorkflowScript: 27: unexpected token: S3Upload @ line 27, column 29.
                       $class: 'S3Upload',

Has anyone run into this before or let me know where shall I look to get some more understanding of how this plugin is supposed to work thru Jenkinsfile?

CodePudding user response:

I haven't used this plugin specifically, but looking at the documentation, you can try something like this:

S3Upload {
    profileName: ‘myawsprofile’,
    ....

If that doesn't work, you can possibly look to using the Pipeline AWS plugin, which is much more popular and has better support/documentation. It also has the ability to do more than just deal with S3, and is simple to use. For your particular case, the related documentation can be found here. Additionally, you might find this answer helpful, since it talks about uploading to S3 end-to-end with the Pipeline AWS plugin.

CodePudding user response:

Used the Pipeline syntax to get the code snippet which I posted into a stage as a step as follows:

stage("publish to s3") {
           steps {
                s3Upload consoleLogLevel: 'INFO', dontSetBuildResultOnFailure: false, dontWaitForConcurrentBuildCompletion: false, entries: [[bucket: 'my-S3-bucket', excludedFile: '', flatten: false, gzipFiles: false, keepForever: false, managedArtifacts: false, noUploadOnFailure: false, selectedRegion: 'us-east-1', showDirectlyInBrowser: false, sourceFile: '**/target/*.jar', storageClass: 'STANDARD', uploadFromSlave: false, useServerSideEncryption: false]], pluginFailureResultConstraint: 'FAILURE', profileName: 'test0-aws', userMetadata: []
                     
            }
}
  • Related