• Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: Major Major
    • s3-plugin
    • None
    • Jenkins 2.46.2
      S3 Plugin 0.10.12
      AWS SDK 1.11.119

      Using the following to upload a JSON file to S3 results in the Metadata Content-Type to be set to application/octet-stream

      step([$class: 'S3BucketPublisher', consoleLogLevel: 'INFO', dontWaitForConcurrentBuildCompletion: false, entries: [[
      bucket: 'x.x.tech',
      excludedFile: '',
      flatten: false,
      gzipFiles: false,
      keepForever: true,
      managedArtifacts: false,
      noUploadOnFailure: true,
      selectedRegion: 'eu-west-1',
      showDirectlyInBrowser: false,
      sourceFile: "path/**",
      storageClass: 'STANDARD',
      uploadFromSlave: false,
      useServerSideEncryption: true
      ]], pluginFailureResultConstraint: 'FAILURE', profileName: 'x-profile', userMetadata: []])
      

      However we'd like to set the Content-Type to application/json. I've had a look around and seen nothing, but looking in the code I see that this should be set automatically, Is there something I'm missing for this to be set correctly?

          [JENKINS-44446] Content-Type not set correctly

          Alexander A added a comment -

          Hi garfty

          You need to do "showDirectlyInBrowser: true" - in this case everything should be ok. Maybe setting `userMedata` to "ContentType: application/json" will be required.

          To be honest I don't know reason behind setting "application/octet-stream" by default. But I believe that it was done on purpose

          Alexander A added a comment - Hi garfty You need to do "showDirectlyInBrowser: true" - in this case everything should be ok. Maybe setting `userMedata` to "ContentType: application/json" will be required. To be honest I don't know reason behind setting "application/octet-stream" by default. But I believe that it was done on purpose

          Gareth Parker added a comment -

          Hi Alexander,

          Thanks for the speedy response, I've just had a chance to test out setting showDirectlyInBrowser: true however it made no difference to the file when uploaded. When I add the following:

          step([$class: 'S3BucketPublisher', consoleLogLevel: 'INFO', dontWaitForConcurrentBuildCompletion: false, entries: [[
          bucket: 'x.x.tech',
          excludedFile: '',
          flatten: false,
          gzipFiles: false,
          keepForever: true,
          managedArtifacts: false,
          noUploadOnFailure: true,
          selectedRegion: 'eu-west-1',
          showDirectlyInBrowser: true,
          sourceFile: "path/**",
          storageClass: 'STANDARD',
          uploadFromSlave: false,
          useServerSideEncryption: true
          ]], pluginFailureResultConstraint: 'FAILURE', profileName: 'x-profile', userMetadata: [
          "ContentType": "application/json"
          ]])
          

          It throws the following error:

          userMetadata: MetadataPair(key: String, value: String)[], dontWaitForConcurrentBuildCompletion: boolean, consoleLogLevel: String, pluginFailureResultConstraint: String): java.lang.UnsupportedOperationException: must specify $class with an implementation of interface java.util.List
          

          I'll keep digging and let you know if I find anything else.

          Gareth Parker added a comment - Hi Alexander, Thanks for the speedy response, I've just had a chance to test out setting  showDirectlyInBrowser: true however it made no difference to the file when uploaded. When I add the following: step([$class: 'S3BucketPublisher' , consoleLogLevel: 'INFO' , dontWaitForConcurrentBuildCompletion: false , entries: [[ bucket: 'x.x.tech' , excludedFile: '', flatten: false , gzipFiles: false , keepForever: true , managedArtifacts: false , noUploadOnFailure: true , selectedRegion: 'eu-west-1' , showDirectlyInBrowser: true , sourceFile: "path/**" , storageClass: 'STANDARD' , uploadFromSlave: false , useServerSideEncryption: true ]], pluginFailureResultConstraint: 'FAILURE' , profileName: 'x-profile' , userMetadata: [ "ContentType" : "application/json" ]]) It throws the following error: userMetadata: MetadataPair(key: String , value: String )[], dontWaitForConcurrentBuildCompletion: boolean , consoleLogLevel: String , pluginFailureResultConstraint: String ): java.lang.UnsupportedOperationException: must specify $ class with an implementation of interface java.util.List I'll keep digging and let you know if I find anything else.

          Gareth Parker added a comment -

          I've finally got around to looking back in to this, and got a little further, now my builds are just unstable

          step([
          $class: 'S3BucketPublisher',
          consoleLogLevel: 'INFO',
          dontWaitForConcurrentBuildCompletion: false,
          entries: [[
          bucket: 'x-bucket',
          excludedFile: '',
          flatten: false,
          gzipFiles: false,
          keepForever: true,
          managedArtifacts: false,
          noUploadOnFailure: true,
          selectedRegion: 'eu-west-1',
          showDirectlyInBrowser: true,
          sourceFile: "path/**/*.json",
          storageClass: 'STANDARD',
          uploadFromSlave: false,
          useServerSideEncryption: true
          ]],
          pluginFailureResultConstraint: 'FAILURE',
          profileName: 'x-profile',
          userMetadata: [[
          "Content-Type": "application/json"
          ]]
          ])

           

          This results in the following:

          ERROR: Failed to upload files java.io.IOException: Call fails for Destination [bucketName=x-bucket, objectName=path/test.json]: java.lang.NullPointerException:: Failed after 5 tries. at hudson.plugins.s3.S3Profile.repeat(S3Profile.java:262) at hudson.plugins.s3.S3Profile.upload(S3Profile.java:155) at hudson.plugins.s3.S3BucketPublisher.perform(S3BucketPublisher.java:254) at org.jenkinsci.plugins.workflow.steps.CoreStep$Execution.run(CoreStep.java:78) at org.jenkinsci.plugins.workflow.steps.CoreStep$Execution.run(CoreStep.java:65) at org.jenkinsci.plugins.workflow.steps.SynchronousNonBlockingStepExecution$1$1.call(SynchronousNonBlockingStepExecution.java:49) at hudson.security.ACL.impersonate(ACL.java:260) at org.jenkinsci.plugins.workflow.steps.SynchronousNonBlockingStepExecution$1.run(SynchronousNonBlockingStepExecution.java:46) at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:473) at java.util.concurrent.FutureTask.run(FutureTask.java:262) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) at java.lang.Thread.run(Thread.java:745) Caused by: java.lang.NullPointerException at hudson.plugins.s3.callable.S3BaseUploadCallable.buildMetadata(S3BaseUploadCallable.java:62) at hudson.plugins.s3.callable.S3UploadCallable.invoke(S3UploadCallable.java:26) at hudson.plugins.s3.callable.S3UploadCallable.invoke(S3UploadCallable.java:14) at hudson.plugins.s3.S3Profile.invoke(S3Profile.java:195) at hudson.plugins.s3.S3Profile.access$000(S3Profile.java:29) at hudson.plugins.s3.S3Profile$1.call(S3Profile.java:158) at hudson.plugins.s3.S3Profile$1.call(S3Profile.java:155) at hudson.plugins.s3.S3Profile.repeat(S3Profile.java:258) ... 12 more

           

          Can't quite see what's causing it to fail.

          Gareth Parker added a comment - I've finally got around to looking back in to this, and got a little further, now my builds are just unstable step([ $class: 'S3BucketPublisher' , consoleLogLevel: 'INFO' , dontWaitForConcurrentBuildCompletion: false , entries: [[ bucket: 'x-bucket' , excludedFile: '', flatten: false , gzipFiles: false , keepForever: true , managedArtifacts: false , noUploadOnFailure: true , selectedRegion: 'eu-west-1' , showDirectlyInBrowser: true , sourceFile: "path /**/ *.json" , storageClass: 'STANDARD' , uploadFromSlave: false , useServerSideEncryption: true ]], pluginFailureResultConstraint: 'FAILURE' , profileName: 'x-profile' , userMetadata: [[ "Content-Type" : "application/json" ]] ])   This results in the following: ERROR: Failed to upload files java.io.IOException: Call fails for Destination [bucketName=x-bucket, objectName=path/test.json] : java.lang.NullPointerException:: Failed after 5 tries. at hudson.plugins.s3.S3Profile.repeat(S3Profile.java:262) at hudson.plugins.s3.S3Profile.upload(S3Profile.java:155) at hudson.plugins.s3.S3BucketPublisher.perform(S3BucketPublisher.java:254) at org.jenkinsci.plugins.workflow.steps.CoreStep$Execution.run(CoreStep.java:78) at org.jenkinsci.plugins.workflow.steps.CoreStep$Execution.run(CoreStep.java:65) at org.jenkinsci.plugins.workflow.steps.SynchronousNonBlockingStepExecution$1$1.call(SynchronousNonBlockingStepExecution.java:49) at hudson.security.ACL.impersonate(ACL.java:260) at org.jenkinsci.plugins.workflow.steps.SynchronousNonBlockingStepExecution$1.run(SynchronousNonBlockingStepExecution.java:46) at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:473) at java.util.concurrent.FutureTask.run(FutureTask.java:262) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) at java.lang.Thread.run(Thread.java:745) Caused by: java.lang.NullPointerException at hudson.plugins.s3.callable.S3BaseUploadCallable.buildMetadata(S3BaseUploadCallable.java:62) at hudson.plugins.s3.callable.S3UploadCallable.invoke(S3UploadCallable.java:26) at hudson.plugins.s3.callable.S3UploadCallable.invoke(S3UploadCallable.java:14) at hudson.plugins.s3.S3Profile.invoke(S3Profile.java:195) at hudson.plugins.s3.S3Profile.access$000(S3Profile.java:29) at hudson.plugins.s3.S3Profile$1.call(S3Profile.java:158) at hudson.plugins.s3.S3Profile$1.call(S3Profile.java:155) at hudson.plugins.s3.S3Profile.repeat(S3Profile.java:258) ... 12 more   Can't quite see what's causing it to fail.

          Ran into a similar issue, when attempting to set 'Cache control' headers during publishing to S3, and eventually figured out that the userMetadata parameter had to be set twice (going by the Jenkins pipeline syntax editor). Oddly enough, it worked.

          Working pipeline step is as follows: 

          step([$class: 'S3BucketPublisher',
           consoleLogLevel: 'INFO',
           dontWaitForConcurrentBuildCompletion: false,
           entries: [[
           bucket: 'example.com',
           excludedFile: '',
           flatten: false,
           gzipFiles: false,
           keepForever: false,
           managedArtifacts: false,
           noUploadOnFailure: true,
           selectedRegion: 'ap-south-1',
           showDirectlyInBrowser: false,
           sourceFile: 'dist/**/*',
           storageClass: 'STANDARD',
           uploadFromSlave: true,
           useServerSideEncryption: false,
           userMetadata: [[key: 'Cache-Control', value: 'max-age=86400']]
           ]],
           profileName: 's3deployer',
           pluginFailureResultConstraint: 'FAILURE',
           userMetadata: [[key: 'Cache-Control', value: 'max-age=86400']]
           ])

           

          Vineet Reynolds Pereira added a comment - Ran into a similar issue, when attempting to set 'Cache control' headers during publishing to S3, and eventually figured out that the userMetadata  parameter had to be set twice (going by the Jenkins pipeline syntax editor). Oddly enough, it worked. Working pipeline step is as follows:  step([$class: 'S3BucketPublisher' , consoleLogLevel: 'INFO' , dontWaitForConcurrentBuildCompletion: false , entries: [[ bucket: 'example.com' , excludedFile: '', flatten: false , gzipFiles: false , keepForever: false , managedArtifacts: false , noUploadOnFailure: true , selectedRegion: 'ap-south-1' , showDirectlyInBrowser: false , sourceFile: 'dist /**/ *' , storageClass: 'STANDARD' , uploadFromSlave: true , useServerSideEncryption: false , userMetadata: [[key: 'Cache-Control' , value: 'max-age=86400' ]] ]], profileName: 's3deployer' , pluginFailureResultConstraint: 'FAILURE' , userMetadata: [[key: 'Cache-Control' , value: 'max-age=86400' ]] ])  

            jimilian Alexander A
            garfty Gareth Parker
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated: