Uploaded image for project: 'Jenkins'
  1. Jenkins
  2. JENKINS-73492

java.io.FileNotFoundException is raised when trying to publish artifacts from remote agents

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: Minor Minor
    • defectdojo-plugin
    • None

      Hi team,

      Thanks to your wonderful plugin for the integration with DefectDojo, it's very helpful.

       

      When I tried to use the plugin to publish the artifacts/reports generated by security scanner tools such as gitleaks, Grype from remote agents, I got the following errors.

       

      ...
      
      java.io.FileNotFoundException: <**REDACTED**>/build/gitleaks.json (No such file or directory)
      	at java.base/java.io.FileInputStream.open0(Native Method)
      	at java.base/java.io.FileInputStream.open(FileInputStream.java:216)
      	at java.base/java.io.FileInputStream.<init>(FileInputStream.java:157)
      	at okio.Okio__JvmOkioKt.source(JvmOkio.kt:181)
      	at okio.Okio.source(Unknown Source)
      	at okhttp3.RequestBody$Companion$asRequestBody$1.writeTo(RequestBody.kt:167)
      	at okhttp3.MultipartBody.writeOrCountBytes(MultipartBody.kt:157)
      	at okhttp3.MultipartBody.writeTo(MultipartBody.kt:93)
      	at okhttp3.internal.http.CallServerInterceptor.intercept(CallServerInterceptor.kt:62)
      	at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:109)
      	at okhttp3.internal.connection.ConnectInterceptor.intercept(ConnectInterceptor.kt:34)
      	at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:109)
      	at okhttp3.internal.cache.CacheInterceptor.intercept(CacheInterceptor.kt:95)
      	at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:109)
      	at okhttp3.internal.http.BridgeInterceptor.intercept(BridgeInterceptor.kt:83)
      	at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:109)
      	at okhttp3.internal.http.RetryAndFollowUpInterceptor.intercept(RetryAndFollowUpInterceptor.kt:76)
      	at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:109)
      	at okhttp3.internal.connection.RealCall.getResponseWithInterceptorChain$okhttp(RealCall.kt:201)
      	at okhttp3.internal.connection.RealCall.execute(RealCall.kt:154)
      	at io.jenkins.plugins.DefectDojo.ApiClient.lambda$upload$2(ApiClient.java:238)
      	at io.jenkins.plugins.DefectDojo.ApiClient.lambda$executeWithRetry$8(ApiClient.java:468)
      	at org.springframework.retry.support.RetryTemplate.doExecute(RetryTemplate.java:329)
      	at org.springframework.retry.support.RetryTemplate.execute(RetryTemplate.java:209)
      	at io.jenkins.plugins.DefectDojo.ApiClient.executeWithRetry(ApiClient.java:468)
      	at io.jenkins.plugins.DefectDojo.ApiClient.upload(ApiClient.java:237)
      	at io.jenkins.plugins.DefectDojo.DefectDojoPublisher.perform(DefectDojoPublisher.java:251)
      	at org.jenkinsci.plugins.workflow.steps.CoreStep$Execution.run(CoreStep.java:101)
      	at org.jenkinsci.plugins.workflow.steps.CoreStep$Execution.run(CoreStep.java:71)
      	at org.jenkinsci.plugins.workflow.steps.SynchronousNonBlockingStepExecution.lambda$start$0(SynchronousNonBlockingStepExecution.java:47)
      	at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:539)
      	at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
      	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136)
      	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
      	at java.base/java.lang.Thread.run(Thread.java:840)
      Finished: FAILURE

      My environment is as below:

       

      • DefectDojo Plugin, version 1.049.v8272429d864a_
      • Jenkins controller, version 2.440.1
      • Jenkins agent, version 3148.v532a_7e715ee3

      It would be great if you could take a look at this error and help me to solve the problem. Thank you so much!

          [JENKINS-73492] java.io.FileNotFoundException is raised when trying to publish artifacts from remote agents

          Eugeniu added a comment -

          I did not test the Plugin with Jenkins Agents and didn't look into the topic. Will have to check what can be the issue and how I can assure that the files are correctly uploaded from remote agents.

          Thanks for reporting, I will check on it and push an update with a fix.

          Eugeniu added a comment - I did not test the Plugin with Jenkins Agents and didn't look into the topic. Will have to check what can be the issue and how I can assure that the files are correctly uploaded from remote agents. Thanks for reporting, I will check on it and push an update with a fix.

          Eugeniu added a comment -

          I'd also suggest to take a look into this documentation, maybe your agent does not have the right to read the file: Jenkins Agent - Controller file acces

          The plugin checks if the file to be uploaded exists, if not found, it stops the execution with a log. In your case, it seems that the file exists on the controller, as the check is passed. So it well may be that the Agent does not have the permission to read the file.

          Eugeniu added a comment - I'd also suggest to take a look into this documentation, maybe your agent does not have the right to read the file: Jenkins Agent - Controller file acces The plugin checks if the file to be uploaded exists, if not found, it stops the execution with a log. In your case, it seems that the file exists on the controller, as the check is passed. So it well may be that the Agent does not have the permission to read the file.

          Markus Winter added a comment -

          The code is written in a way that makes it impossible to upload files from remote agents. You have to consider that all the code in APIClient is running on the controller and not the agent. In line https://github.com/jenkinsci/defectdojo-plugin/blob/80a4d1944a023cc2faad4ecacfc66ba9f37c1421/src/main/java/io/jenkins/plugins/DefectDojo/ApiClient.java#L193C14-L193C22 you check if the file exists, it returns true because FilePath knowns that the file is remove and so it will delegate the exists call to the agent. Here https://github.com/jenkinsci/defectdojo-plugin/blob/80a4d1944a023cc2faad4ecacfc66ba9f37c1421/src/main/java/io/jenkins/plugins/DefectDojo/ApiClient.java#L222C45-L222C53 you use "artifact.getRemote()" which just returns a string with the absolute path on the remote agent. But as you run on the controller the file doesn't exist.

          You will need to either transfer the file first from the agent to the controller, which not be the best idea when the file is big or you will need to make sure to execute the upload directly from the agent (use FilePath.act() for this, it might mean that you have to delay object creation because the objects are not serializable)

          Markus Winter added a comment - The code is written in a way that makes it impossible to upload files from remote agents. You have to consider that all the code in APIClient is running on the controller and not the agent. In line https://github.com/jenkinsci/defectdojo-plugin/blob/80a4d1944a023cc2faad4ecacfc66ba9f37c1421/src/main/java/io/jenkins/plugins/DefectDojo/ApiClient.java#L193C14-L193C22 you check if the file exists, it returns true because FilePath knowns that the file is remove and so it will delegate the exists call to the agent. Here https://github.com/jenkinsci/defectdojo-plugin/blob/80a4d1944a023cc2faad4ecacfc66ba9f37c1421/src/main/java/io/jenkins/plugins/DefectDojo/ApiClient.java#L222C45-L222C53 you use "artifact.getRemote()" which just returns a string with the absolute path on the remote agent. But as you run on the controller the file doesn't exist. You will need to either transfer the file first from the agent to the controller, which not be the best idea when the file is big or you will need to make sure to execute the upload directly from the agent (use FilePath.act() for this, it might mean that you have to delay object creation because the objects are not serializable)

          Eugeniu added a comment -

          mawinter69 thanks for your input, I will be looking into it and will add support for Agent Uploads with next releases.

          Eugeniu added a comment - mawinter69 thanks for your input, I will be looking into it and will add support for Agent Uploads with next releases.

            eu_david Eugeniu
            yutayamate Yuta
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated: