jfrog-cli icon indicating copy to clipboard operation
jfrog-cli copied to clipboard

build.branch property to uploaded build artifacts not working

Open vinaysaiadepu opened this issue 3 years ago • 10 comments

Describe the bug Your new release 1.45.1 shows "build.branch" property will upload to artifactory along with artifacts, but it is not working when tested. Screenshot 2021-03-16 at 6 49 27 PM

Expected behavior In new 1.45.1 release a property build.branch has to upload in Artifactory along with artifacts.

Screenshots Adding screenshot of properties section which does not show build.branch Screenshot 2021-03-16 at 6 42 07 PM

Versions

  • JFrog CLI version: 1.45.1
  • JFrog CLI operating system: Linux
  • Artifactory Version: Enterprise Plus 7.10.6

Please help me how exactly we need to use this feature.

vinaysaiadepu avatar Mar 16 '21 13:03 vinaysaiadepu

Thanks for reporting this @vinaysaiadepu, Which command did you use to upload the files? Does the command include the --build-name and --build-number command options? The vcs.branch properly is added only when the artifacts uploaded are associated with a build. Also, did you run the command from a directory inside a git project? The branch value is picked up by jfrog-cli from the local .git directory.

eyalbe4 avatar Mar 16 '21 14:03 eyalbe4

Thanks for reporting this @vinaysaiadepu, Which command did you use to upload the files? Does the command include the --build-name and --build-number command options? The vcs.branch properly is added only when the artifacts uploaded are associated with a build. Also, did you run the command from a directory inside a git project? The branch value is picked up by jfrog-cli from the local .git directory.

I am using below jfrog-cli commands in my jenkins pipeline for build publish to artifactory.

jfrog rt bce $JFROG_CLI_BUILD_NAME $JFROG_CLI_BUILD_NUMBER jfrog rt bp $JFROG_CLI_BUILD_NAME $JFROG_CLI_BUILD_NUMBER

Above commands are working fine and artifacts are uploading as expected. But build.branch property is not showing up under properties tab.

Also I tried --env-include to above cmds but are not working.

vinaysaiadepu avatar Mar 16 '21 15:03 vinaysaiadepu

@vinaysaiadepu, The 'jfrog rt bce' command only reads the environment variables on the machine and attaches them to the build-info. The 'jfrog rt bp' command publishers the build-info to Artifactory. The command which uploads the files is 'jfrog rt u'. Search for this command in your pipeline. If executed while inside a local git repository and used the --build-name and --build-number options, then the vcs.branch should be attaches to the uploaded artifacts. I suggest you try this out from your terminal (outside of Jenkins) for easier troubleshooting.

eyalbe4 avatar Mar 16 '21 15:03 eyalbe4

@vinaysaiadepu, The 'jfrog rt bce' command only reads the environment variables on the machine and attaches them to the build-info. The 'jfrog rt bp' command publishers the build-info to Artifactory. The command which uploads the files is 'jfrog rt u'. Search for this command in your pipeline. If executed while inside a local git repository and used the --build-name and --build-number options, then the vcs.branch should be attaches to the uploaded artifacts. I suggest you try this out from your terminal (outside of Jenkins) for easier troubleshooting.

Thanks for quick reply @eyalbe4 I tried below cmd in my local git repo but didn't work jfrog rt u property-test 21 -> here 'property-test' is my build-name and '21' is my build-number

output for above cmd is:

Log path: /Users/vinay/.jfrog/logs/jfrog-cli.2021-03-16.22-29-18.2919.log { "status": "failure", "totals": { "success": 0, "failure": 0 } }

cat /Users/vinay/.jfrog/logs/jfrog-cli.2021-03-16.22-29-18.2919.log

[Error] Path does not exist: property-test [Error] Path does not exist: property-test


From JFrog confluence page. I can see there are 7 examples for "jfrog rt u" cmd which doesn't match my requirement. Please provide me exact cmd for uploading/pushing the git branch-name into artifactory as a property.

Thanks in advance.

vinaysaiadepu avatar Mar 16 '21 17:03 vinaysaiadepu

@vinaysaiadepu, The syntax of your upload command is wrong - the first arg the command receivs is the source parh (on your local file system) and the second arg is the target path (on Artifactory). You however provided the build name and build number as arguments.

eyalbe4 avatar Mar 16 '21 17:03 eyalbe4

@vinaysaiadepu, The syntax of your upload command is wrong - the first arg the command receivs is the source parh (on your local file system) and the second arg is the target path (on Artifactory). You however provided the build name and build number as arguments.

So I should provide source path I agree, but which folder of my repo should be that source? Give me some more clarity or some reference links if any.

Ex. jfrog rt u "/src/path/" "target_path" property-test 21 -> here 'property-test' is my build-name and '21' is my build-number.

Here what should be my path which has "build.branch" ?

vinaysaiadepu avatar Mar 16 '21 17:03 vinaysaiadepu

@vinaysaiadepu, I'm not sure I understand your question. All the information about the upload command is documented in this link - including the arguments amd options - https://www.jfrog.com/confluence/display/CLI/CLI+for+JFrog+Artifactory#CLIforJFrogArtifactory-UploadingFiles As for the vcs.branch prop, you don't provide it. It is picked up by the command automatically. See my previous comments in this issue explaining how this is done.

eyalbe4 avatar Mar 16 '21 18:03 eyalbe4

@vinaysaiadepu, I'm not sure I understand your question. All the information about the upload command is documented in this link - including the arguments amd options - https://www.jfrog.com/confluence/display/CLI/CLI+for+JFrog+Artifactory#CLIforJFrogArtifactory-UploadingFiles As for the vcs.branch prop, you don't provide it. It is picked up by the command automatically. See my previous comments in this issue explaining how this is done.

Thanks @eyalbe4 I have done all the ground work using the confluence link but I didn't get the solution.

In the release 1.45.0 jfrog has mentioned that this feature was added, but no documentation or cmd provided in confluence.

Appreciate if someone @jfrog can provide me the exact use case for this issue.

@jfrogsolutionci @jfrog-demo @IL-Automation @IL-Automation2 please help as we are implementing jfrog-cli in our organization and just stuck with this feature.

vinaysaiadepu avatar Mar 16 '21 18:03 vinaysaiadepu

@vinaysaiadepu, here is a simple template for you to fill: jfrog rt upload "path/to/local/files" "path/in/artifactory" --build-name=myBuildName --build-number=1 Remember to make sure you run this command in the same location that your .git is located.

Or-Geva avatar Mar 17 '21 08:03 Or-Geva

I had this same problem along with one other.

  • The vcs.branch property in Artifactory was not being set after using jf rt upload in my Jenkins pipeline.
  • The branch value was empty in my build info JSON in Artifactory after using jf rt build-add-git in my Jenkins pipeline.

It was frustrating until I found out about this info...

When the Jenkins Git plugin clones a repo, it checks out a specific commit, rather than HEAD of the repo. This puts the repo in a "detached" state, so if you want to perform further git operations on the repo you need to attach to a branch with a checkout command in a shell step. - Source

I found that when the repo is in a detached HEAD state, the jf rt upload and jf rt build-add-git CLI commands are unable to capture the branch info when executed in my Jenkins pipeline.

This is how I fixed it...

bat "git checkout ${env.BRANCH_NAME}" // Checkout as branch name so "rt upload" and "rt build-add-git" can capture the branch name
jf(['rt', 'upload', <args>])
jf(['rt', 'build-add-git', env.JOB_NAME, env.BUILD_NUMBER, env.WORKSPACE])
jf(['rt', 'build-publish', env.JOB_NAME, env.BUILD_NUMBER, "--build-url=${env.BUILD_URL}", "--server-id=${serverId}"])
bat "git checkout ${env.GIT_COMMIT} --quiet" // Restore original detached HEAD state

Edit: An alternate solution would be to add the option called "Check out to matching local branch" to the pipeline's job configuration. This will checkout the repository as a local branch rather than a detached HEAD.

crgilman avatar Mar 25 '24 20:03 crgilman