jfrog / jfrog-cli

JFrog CLI is a client that provides a simple interface that automates access to the JFrog products.
https://www.jfrog.com/confluence/display/CLI/JFrog+CLI
Apache License 2.0
524 stars 223 forks source link

Parallel stages in Jenkins fails to publish build info to Artifactory #793

Open anhuong opened 4 years ago

anhuong commented 4 years ago

Hello!

I'm running a job in Jenkins that has parallel stages where we are uploading different artifacts to Artifactory and then publishing the build information. The upload is successful but publishing the build info subsequently fails with error: [Error] open /tmp/jfrog/builds/c3BlZWNoIDo6IGRlcGxveV82OTc1/partials/details: no such file or directory. Since the upload succeeded, the build details should exist to publish the build record. We are running the jfrog-cli directly in Jenkins.

jfrog version 1.37.0 We are running:

jfrog rt config artifactory-server \
  --interactive=false \
  --url="https://na.artifactory.swg-devops.com/artifactory" \
  --apikey="$artifactory_api_key"

echo "Testing connection to Artifactory server: https://na.artifactory.swg-devops.com/artifactory"
jfrog rt ping >/dev/null 2>&1 || retval=$?
if ((retval != 0)); then
  die "Failed to connect to Artifactory. Check that the credential is correct and Artifactory is up and running."
fi
success "Artifactory server available."

jfrog rt upload \
  --build-name "$build_name" \
  --build-number "$build_number" \
  "$full_artifact_path_name" \
  "${artifactory_repo}/${artifactory_repo_path}/$artifact_name"

jfrog rt build-publish --build-url="$build_url" "$build_name" "$build_number"

And the output is:

[parallel stages] 
# Successful stage run through Artifactory

 Checking for Artifactory API key and required arguments...
 Now creating the artifact, dvt-yamlFile-jenkins-speech-deploy-6975-dvt-stt-6975.zip...
   adding: rendered-configs/public/dvt/50_stt_dvt_job.yaml  (in=1168) (out=452) (deflated 61%)
 total bytes=1168, compressed=452 -> 61% savings
 Artifact successfully created.

 Will now deploy the artifact to:
 - repository: https://na.artifactory.swg-devops.com/artifactory/wcp-watson-core-hyboria-artifacts-generic-virtual
 - path: speech/deploy
 - build name: speech :: deploy
 - build number: 6975

 Testing connection to Artifactory server: https://na.artifactory.swg-devops.com/artifactory
Artifactory server available.
 [Info] [Thread 2] Uploading artifact: dvt-yamlFile-jenkins-speech-deploy-6975-dvt-stt-6975.zip
 {
   "status": "success",
   "totals": {
     "success": 1,
     "failure": 0
   }
 }
 [Info] Deploying build info...
 [Info] Build info successfully deployed. Browse it in Artifactory under https://na.artifactory.swg-devops.com/artifactory/webapp/builds/speech :: deploy/6975

 Artifact successfully deployed to Artifactory.

 Your artifact, dvt-yamlFile-jenkins-speech-deploy-6975-dvt-stt-6975.zip, can be found at https://na.artifactory.swg-devops.com/artifactory/wcp-watson-core-hyboria-artifacts-generic-virtual/speech/deploy/dvt-yamlFile-jenkins-speech-deploy-6975-dvt-stt-6975.zip

# Failed stage run through Artifactory

 Checking for Artifactory API key and required arguments...
 Now creating the artifact, dvt-yamlFile-jenkins-speech-deploy-6975-dvt-tts-6975.zip...
   adding: rendered-configs/public/dvt/50_tts_dvt_job.yaml  (in=1168) (out=452) (deflated 61%)
 total bytes=1168, compressed=452 -> 61% savings
 Artifact successfully created.

 Will now deploy the artifact to:
 - repository: https://na.artifactory.swg-devops.com/artifactory/wcp-watson-core-hyboria-artifacts-generic-virtual
 - path: speech/deploy
 - build name: speech :: deploy
 - build number: 6975

 Testing connection to Artifactory server: https://na.artifactory.swg-devops.com/artifactory

Artifactory server available.
 [Info] [Thread 2] Uploading artifact: dvt-yamlFile-jenkins-speech-deploy-6975-dvt-tts-6975.zip
 {
   "status": "success",
   "totals": {
     "success": 1,
     "failure": 0
   }
 }
 [Error] open /tmp/jfrog/builds/c3BlZWNoIDo6IGRlcGxveV82OTc1/partials/details: no such file or directory

Any help would be great. Would upgrading to the latest version 1.38.2 help?

anhuong commented 3 years ago

@eyalbe4 Have you seen this issue before?

yahavi commented 3 years ago

@anhuong thanks for reporting this issue. The JFrog CLI collects the build information during the build and stores it in a temporary folder in the agent. If you are using parallel stages where each step is running on a different agent, this behavior wouldn't work by default. You can try, as a workaround, to configure your JFrog CLI temporary folder to be under your shared workspace. You can achieve this by setting JFROG_CLI_TEMP_DIR environment variable to be a path on your job's workspace, or a path to another shared folder.

A better approach would be to upload the files and publish the build info using the Jenkins Artifactory plugin. The Jenkins Artifactory plugin is already save the build info in a shared folder.

Please notice that there is one drawback using multi-agent build approach - The agent information in the build info (like environment variables) may be related to the agent that did publish it. Thus, we recommend you to upload the build artifacts and publish the build info in the same agent.

By the way, we are working on supporting aggregation of associated builds in the JFrog CLI. This feature will be available in the near future.

Please let me know if this information helps.

anhuong commented 3 years ago

@yahavi I appreciate you taking a look at this and responding! You make some excellent points, we previously were using the Jenkins Artifactory plugin and it worked superbly. However, we have a CLI version of our common library methods and moved to using jfrog-cli so users could utilize the same commands via CLI and Jenkins.

Furthermore, you make a great point about how the agents may be changing due to the parallel stages and this may make it hard for jfog to keep track of it's temp dir. However, we are running the jfrog commands in succession each time. jfrog rt config artifactory-server jfrog rt upload jfrog rt build-publish This would make me think that there should not be an issue with a temp dir since we are running the config, upload, and publish each time.

We have added the JFROG_CLI_TEMP_DIR` to our automation. Thanks for the suggestion! Will try to remember to update this issue with how it goes.