Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to run git diff-tree against master branch in jenkins?

I would like to be able to see which files have changed between my current branch and the master branch during a jenkins build.

in my jenkinsfile i have the below code.

git diff-tree -r --no-commit-id --name-only ${env.GIT_COMMIT} origin/master

but i get the below error

fatal: ambiguous argument 'master': unknown revision or path not in the working tree.

Any help would be appreciated..it'd be great if someone could tell me what i'm doing wrong or devise an alternate solution that will give me the filepaths of files that have changed.

fyi, the above command works locally, but not in jenkins.

like image 325
gurpsone Avatar asked Jan 26 '23 21:01

gurpsone


1 Answers

I finally found the fix for this. @vonc pointed me in the right direction, but the link he provided didn't make any sense.

Here's the link that helped me.

https://issues.jenkins-ci.org/browse/JENKINS-45666?page=com.atlassian.jira.plugin.system.issuetabpanels%3Achangehistory-tabpanel

You have to add a refspec in the jenkins settings for the project. If you are using github organisations you have to apply in the organisations settings as you can't change a specifc repos settings. Anyway, this works for me.

Add this as a refspec.

+refs/heads/master:refs/remotes/@{remote}/master
like image 74
gurpsone Avatar answered Jan 29 '23 10:01

gurpsone