How give aws credential to jenkins pipeline?

I have following configuration in my jenkins pipeline

s3Upload( file:'ok.txt', bucket:'my-buckeck', path:'file.txt')

Problem is s3Upload function is not taking AWS access keys that i have stored in jenkins

i tied with following code

    withAWS(profile:'Test Publisher') {
    s3Upload( file:'ok.txt', bucket:'my-buckeck', path:'file.txt')

}

s3 profile

my s3 profile in jenkins is like that. still am getting profile file could not find error. How can i upload file from jenkins to s3 using s3Upload function ?


To be able to upload to S3, you need to save your credentials in environment variables on your Jenkins:

AWS_DEFAULT_REGION=<region of bucket>

AWS_ACCESS_KEY_ID=<aws id>

AWS_SECRET_ACCESS_KEY=<your s3 access key>

To do that, just go to Jenkins - Manage Jenkins - Configure System - Global properties - Environment variables


I think you may have confused the S3 Publisher plugin with the AWS plugin.

That screenshot is from the S3 Publisher plugin, https://wiki.jenkins.io/display/JENKINS/S3+Plugin. There is a warning not to update to latest version. Looks like compatibility for pipeline is broken, there is this warning "Version 0.10.11 (Dec 31, 2016) - do not update - backward compatibility for pipeline scripts are broken".

However, it looks like your pipeline code is for the Jenkins AWS plugin. https://github.com/jenkinsci/pipeline-aws-plugin. To use credentials with that plugin you must do one of the following:

  1. store access key, secret key in Jenkins credential store.
  2. read from Jenkins' AWS config file.

These options are documented in the plugin README https://github.com/jenkinsci/pipeline-aws-plugin

Use Jenkins UsernamePassword credentials information (Username: AccessKeyId, Password: SecretAccessKey):    
withAWS(credentials:'nameOfSystemCredentials') {
    // do something
}

Use profile information from ~/.aws/config:
withAWS(profile:'myProfile') {
    // do something
}

"profile" is the profile section of your AWS config file. http://docs.aws.amazon.com/cli/latest/userguide/cli-multiple-profiles.html

Then you can use the S3 upload feature. https://github.com/jenkinsci/pipeline-aws-plugin#s3upload