jfrog / jenkins-artifactory-plugin

Jenkins artifactory plugin
http://jenkins-ci.org/
114 stars 187 forks source link

FileNotFoundException in rtGradleRun breaks build job after update to Jenkins 2.426.3 and Plugin 4.0.3 #918

Closed jekkel closed 7 months ago

jekkel commented 8 months ago

After last updates of Jenkins (due to CVE) and artifactory plugins most of our builds fail when running rtGradleRun step with a FileNotFoundException:

java.io.FileNotFoundException: /tmp/workspace/<redacted>_PR-5@tmp/artifactory/buildInfo3731151964641359239.properties (No such file or directory)
    at java.base/java.io.FileOutputStream.open0(Native Method)
    at java.base/java.io.FileOutputStream.open(FileOutputStream.java:293)
    at java.base/java.io.FileOutputStream.<init>(FileOutputStream.java:235)
    at java.base/java.io.FileOutputStream.<init>(FileOutputStream.java:184)
    at org.jfrog.build.extractor.clientConfiguration.ArtifactoryClientConfiguration.persistToPropertiesFile(ArtifactoryClientConfiguration.java:241)
Caused: java.lang.RuntimeException
    at org.jfrog.build.extractor.clientConfiguration.ArtifactoryClientConfiguration.persistToPropertiesFile(ArtifactoryClientConfiguration.java:244)
    at org.jfrog.hudson.util.ExtractorUtils.savePropertiesToFile(ExtractorUtils.java:587)
    at org.jfrog.hudson.util.ExtractorUtils.persistConfiguration(ExtractorUtils.java:565)
    at org.jfrog.hudson.pipeline.common.executors.EnvExtractor.persistConfiguration(EnvExtractor.java:96)
    at org.jfrog.hudson.pipeline.common.executors.EnvExtractor.execute(EnvExtractor.java:75)
Also:   org.jenkinsci.plugins.workflow.actions.ErrorAction$ErrorId: 0f79921b-ba99-4143-addc-0965d31c418f
Caused: java.lang.RuntimeException
    at org.jfrog.hudson.pipeline.common.executors.EnvExtractor.execute(EnvExtractor.java:77)
    at org.jfrog.hudson.pipeline.common.executors.GradleExecutor.execute(GradleExecutor.java:73)
    at org.jfrog.hudson.pipeline.declarative.steps.gradle.GradleStep$Execution.runStep(GradleStep.java:128)
    at org.jfrog.hudson.pipeline.declarative.steps.gradle.GradleStep$Execution.runStep(GradleStep.java:113)
    at org.jfrog.hudson.pipeline.ArtifactorySynchronousNonBlockingStepExecution.run(ArtifactorySynchronousNonBlockingStepExecution.java:55)
    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

To Reproduce The build jobs have been working before the updates. The build job in question is:

The following stage content raises the error on the rtGradleRun step:

                        rtBuildInfo(captureEnv: true)
                        rtGradleDeployer(id: 'GRADLE_DEPLOYER', repo: '<redacted>', serverId: '<redacted>')
                        rtGradleResolver(id: 'GRADLE_RESOLVER', repo: '<redacted>', serverId: '<redacted>')
                        rtGradleRun(
                                tasks: "<redacted>",
                                switches: "<redacted>",
                                deployerId: 'GRADLE_DEPLOYER',
                                resolverId: 'GRADLE_RESOLVER',
                                usesPlugin: true,
                                useWrapper: true
                        )
                        rtDockerPush(
                                image: dockerFullImageName,
                                targetRepo: '<redacted>',
                                serverId: '<redacted>'
                        )
                        rtPublishBuildInfo(serverId: '<redacted>')

The stage definition resides in a shared pipeline included via shared pipeline library. The failure occurs also if the build steps are inlined into the pipeline natively.

I was able to verify that the mentioned "tmp" folder exists and (if rtGradleRun step is executed) the file is actually there, too. But the file is empty. Here is the file listing on the remote after the failure occured:

/tmp/workspace/<redacted>_PR-5@tmp$ find .
.
./artifactory
./artifactory/buildInfo3731151964641359239.properties
./artifactory/deployable.artifacts10392868487987619035.json
./artifactory/generated.build.info2587738024583844316.json
./artifactory/artifactory-pipeline-cache
./artifactory/artifactory-pipeline-cache/16
./artifactory/artifactory-pipeline-cache/16/rtBuildInfo_VGltZSBTZXJpZXMgU2VydmljZXMgOjogZmlsZS1zZXJ2aWNlIDo6IFBSLTVfMTY
./artifactory/artifactory-pipeline-cache/16/rtGradleResolver_R1JBRExFX1JFU09MVkVS
./artifactory/artifactory-pipeline-cache/16/rtGradleDeployer_R1JBRExFX0RFUExPWUVS
./artifactory/deployable.artifacts.map5855963137668782427.json

All files in ./artifactory are empty (0 bytes), the files in ./artifactory/artifactory-pipeline-cache/16 are not empty. The files are owned, readable and writable by user jenkins, the remote Jenkins java process runs on Java 21 as user jenkins.

I was also able to launch a jshell on the agent under user jenkins runs with and I was able to manually execute the code which is told to trigger the error here, without the exception being raised:

java.io.FileOutputStream fos = new java.io.FileOutputStream(new java.io.File("/tmp/workspace/<job>/artifactory/buildInfo3731151964641359239_2.properties")
fos.write(102)
fos.flush()
for.close()

And the file has been created and was non-empty.

This issue seems very similar to #910 . And it's still open as JENKINS-72471

Expected behavior The build should not fail on this exception, gradle build should be invoked.

Versions

schaarda commented 8 months ago

I just want to add an additional curiosity which might help to locate the problem: We have a Windows Master and Linux Slaves. The file in the FileNotFoundException is "c:\home\". So a mix up between FileSystem from the master and path on the slave.

swamygoud18 commented 8 months ago

yea seems the rtMaven is not an issue and we see this failing with rtGradleRun @yahavi.

WillSmith0327 commented 8 months ago

My team is also facing a FileNotFoundException issue with rtGradle. Any idea when this issue might be resolved? Thank you.

Or-Geva commented 7 months ago

@jekkel, @swamygoud18 & @WillSmith0327 Thank you all for reporting this issue, Artifactory Jenkins plugin 4.0.4 has been released, including a fix for this issue. Feel free to upgrade. We'd appreciate your feedback on that.

schaarda commented 7 months ago

Works for me, thanks.

jekkel commented 7 months ago

Works for us, too. Thanks!