Unable to run git lower level commands during Gitlab CI
Summary
Unable to run git lower level commands, specifically git-show-ref
and git-merge-base
during Gitlab CI. WE are looking to script and ensure feature branches are rebased before being able to be merged into master.
Steps to reproduce
See .gitlab-ci.yml
below...
.gitlab-ci.yml
test:
tags:
- cluster
- k8s
stage: test
script:
- MASTER_SHA1=$(git show-ref --heads -s $CI_MERGE_REQUEST_TARGET_BRANCH_NAME)
- MERGE_BASE_SHA1=$(git merge-base $CI_MERGE_REQUEST_TARGET_BRANCH_NAME $CI_MERGE_REQUEST_SOURCE_BRANCH_NAME)
- if [ "${MASTER_SHA1}" = "${MERGE_BASE_SHA1}" ]; then echo "Branch rebased ok to merge." && exit 0; else echo "Branch not rebased onto origin/master!" exit 1; fi
only:
- merge_requests
- branches
Actual behavior
ERROR: Job failed: command terminated with exit code 1
Expected behavior
Git lower level commands to work.
Relevant logs and/or screenshots
job log
[0KRunning with gitlab-runner 12.0.1 (0e5417a3)
[0;m[0K on gitlab-runner-d9cc658f5-lwrvf fiQrbGPn
[0;msection_start:1564492810:prepare_executor
[0K[0KUsing Kubernetes namespace: default
[0;m[0KUsing Kubernetes executor with image registry.bouncex.net/devops/gitlab-runner/k8s-executor:latest ...
[0;msection_end:1564492810:prepare_executor
[0Ksection_start:1564492810:prepare_script
[0KWaiting for pod default/runner-fiqrbgpn-project-12-concurrent-0lfjrl to be running, status is Pending
Waiting for pod default/runner-fiqrbgpn-project-12-concurrent-0lfjrl to be running, status is Pending
Running on runner-fiqrbgpn-project-12-concurrent-0lfjrl via gitlab-runner-d9cc658f5-lwrvf...
section_end:1564492816:prepare_script
[0Ksection_start:1564492816:get_sources
[0K[32;1mFetching changes...[0;m
Initialized empty Git repository in /builds/platformx/chart/.git/
[32;1mCreated fresh repository.[0;m
From https://gitlab.bouncex.net/platformx/chart
* [new branch] feature/DT-786-helm-chart -> origin/feature/DT-786-helm-chart
* [new branch] master -> origin/master
* [new tag] 0.0.3 -> 0.0.3
* [new tag] 0.0.4 -> 0.0.4
* [new tag] 0.0.5 -> 0.0.5
[32;1mChecking out 6ce6e8e9 as feature/DT-786-helm-chart...[0;m
[32;1mSkipping Git submodules setup[0;m
section_end:1564492817:get_sources
[0Ksection_start:1564492817:restore_cache
[0Ksection_end:1564492817:restore_cache
[0Ksection_start:1564492817:download_artifacts
[0Ksection_end:1564492817:download_artifacts
[0Ksection_start:1564492817:build_script
[0K[32;1m$ MASTER_SHA1=$(git show-ref --heads -s $CI_MERGE_REQUEST_TARGET_BRANCH_NAME)[0;m
section_end:1564492818:build_script
[0Ksection_start:1564492818:after_script
[0Ksection_end:1564492818:after_script
[0Ksection_start:1564492818:upload_artifacts_on_failure
[0Ksection_end:1564492818:upload_artifacts_on_failure
[0K[31;1mERROR: Job failed: command terminated with exit code 1
[0;m
Environment description
This is a custom Gitlab enterprise installation on Kubernetes.
Used GitLab Runner version
Running with gitlab-runner 12.0.1 (0e5417a3)
on gitlab-runner-d9cc658f5-lwrvf fiQrbGPn
Using Kubernetes namespace: default
Using Kubernetes executor with image registry.bouncex.net/devops/gitlab-runner/k8s-executor:latest ...
Waiting for pod default/runner-fiqrbgpn-project-12-concurrent-05bnmm to be running, status is Pending
Running on runner-fiqrbgpn-project-12-concurrent-05bnmm via gitlab-runner-d9cc658f5-lwrvf...