11

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 ?

open source guy
  • 229
  • 1
  • 2
  • 5

2 Answers2

10

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

red.avtovo
  • 201
  • 1
  • 3
4

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

Mike Marseglia
  • 913
  • 8
  • 18
  • I'm using the `withAWS` step and have AWS credentials with name `accesskey` and ID `jenkins`. When I call it as `withAWS(credentials:'jenkins')` or as `withAWS(credentials:'accesskey')` I keep hitting this exception. The credentials look good per my Jenkins mgmt console (there's a log saying last used successfully with a recent time). What could I be missing? – scorpiodawg Mar 13 '19 at 17:09
  • 1
    @scorpiodawg your question sounds a bit different than the original. Could you start a new question with as much info as possible? – Mike Marseglia Mar 14 '19 at 18:48
  • I asked this here: https://serverfault.com/questions/958350/jenkins-global-aws-credentials-not-working-via-withaws-step @mike-marseglia – scorpiodawg Mar 14 '19 at 22:24