I encountered a problem about GitlabCI and I was hoping someone could help me with that.
The thing is, I want to run a shell script that compare the source branch & target branch in GitlabCI runner when the job is triggered. The .gitlab-ci.yml
will look like this.
testJob: // the name of the CI/CD job
only:
refs:
- merge_requests
change:
- a/json/folder/*
before_script:
... // some action
script:
- bash ./xxx.sh
This job will be triggered if this is a merge request and if there's any changes in the folder that holds a bunch of json files. And then, it will run the shell script.
Inside the shell script, I was going to compare the source and target branch to get the list of modified json files, so I run this command in the shell script.
current_branch=`git rev-parse --abbrev-ref HEAD` // to get the current branch name, i.e. the source branch
diff_message=`git diff --name-only --diff-filter=AM origin/develop..origin/$CI_COMMIT_REF_NAME`
The target branch will be fixed to develop for some reasons. This piece of code works just fine on local but crashes on the GitlabCI runner. So I went to Gitlab to see what's going on and I saw the error message as follows.
fatal: ambiguous argument 'origin/develop..origin/fix/json': unknown revision or path not in the working tree.
Use '--' to separate paths from revisions, like this:
'git <command> [<revision>...] -- [<file>...]'
My friend told me that the runner will only load the current branch (the source branch of merge request) but not the target branch (develop, in this case). Is it true? If it is true, how am I to get GitlabCI runner to load it. And if it's not possible, is there any alternative for me to get the list of modified json files between two branches?
Thank you.