4

I am trying to get git difference between master and feature branch but getting the error "command not found" using below mentioned command:

COMMIT_CHANGE_SET = sh(returnStdout: true, script: 'git diff --name-only origin/master...$current_branch').trim()

As, I am able to get last commit changes using the below-mentioned command.

COMMIT_CHANGE_SET = sh(returnStdout: true, script: 'git diff-tree --no-commit-id --name-only -r HEAD').trim()

Jenkins pipeline git syntax command to get a difference master and feature branch

Shashi B
  • 115
  • 1
  • 2
  • 10

1 Answers1

1

Replace 'with " in code below:

COMMIT_CHANGE_SET = sh(returnStdout: true, script: "git diff --name-only $current_branch origin/master").trim()

Problem is you have to use " to be able to pass parameter.

Sers
  • 12,047
  • 2
  • 12
  • 31
  • I tried command inside " " , but getting error: ERROR: ' [Pipeline] sh + git diff --name-only origin/master...DRG-111 fatal: ambiguous argument 'origin/master...DRG-111': unknown revision or path not in the working tree. Use '--' to separate paths from revisions, like this: 'git [...] -- [...]' [Pipeline] } ' – Shashi B Feb 21 '19 at 08:42
  • `COMMIT_CHANGE_SET = sh(returnStdout: true, script: "git diff --name-only $current_branch origin/master").trim() ` – Sers Feb 21 '19 at 09:29
  • Updated code still getting the same error: `+ git diff --name-only DRG-111 origin/master fatal: ambiguous argument 'origin/master': unknown revision or path not in the working tree. Use '--' to separate paths from revisions, like this: 'git [...] -- [...]'` – Shashi B Feb 21 '19 at 09:36
  • @ShashiB check [here](https://stackoverflow.com/questions/45096755/fatal-ambiguous-argument-origin-unknown-revision-or-path-not-in-the-working/45096973) – Sers Feb 21 '19 at 09:40
  • 1
    I tried which are mentioned in the [here] (https://stackoverflow.com/questions/45096755/fatal-ambiguous-argument-origin-unknown-revision-or-path-not-in-the-working/45096973) I am getting git difference using command on my local machin `git diff origin/master` and `git diff current_branch origin/master` but same command is not working in Jenkinsfile and getting error: ** fatal: ambiguous argument 'origin/master': unknown revision or path not in the working tree ** – Shashi B Feb 21 '19 at 10:11