0

My goal is to create Gitlab yml file in order to automatically merge code from release to master branch which will be run on a schedule (once a week)

Here is my .gitlab-ci.yml:

image: "python:3.8"
stages:
  - build
  - test
  - release

Build:
  stage: build
  script:
    - <some code here>

Test:
  stage: test
  script:
    - <some code here>

job:on-schedule:
  stage: release
  only:
    - schedules
  script:
    - git config --global user.email myEmail@gmail.com
    - git config --global user.name "myUserName"
    - git checkout release
    - git checkout master
    - git merge release

But I'm getting the following error:

error: pathspec 'release' did not match any file(s) known to git
Cleaning up file based variables
00:00
ERROR: Job failed: exit code 1

. I'd appreciate it if you have any ideas on how to fix that.

Valentyn
  • 562
  • 1
  • 7
  • 21
  • You should consider banning "It's not working" from your vocabulary on Q&A sites like SO, at least when used on its own. [It does not accurately describe your problem](http://idownvotedbecau.se/itsnotworking/) – Zeitounator Nov 28 '20 at 13:53
  • 1
    @Zeitounator Thank you for your comment, I've added my error log information – Valentyn Nov 28 '20 at 13:57

1 Answers1

0

By default, gitlab-ci does a shallow clone, and so the error you're seeing of:

error: pathspec 'release' did not match any file(s) known to git

is accurate because the release branch does not exist locally on the runner.

To resolve this, you can just update the lines to:

    - git checkout origin/release
    - git checkout origin/master

which will pull the latest branches from the repository directly instead.

Rekovni
  • 6,319
  • 3
  • 39
  • 62
  • Thank you for your response! But how to push these changes to a remote repo using .gitlab-ci.yml? – Valentyn Dec 01 '20 at 12:04
  • 1
    Have a look at https://stackoverflow.com/questions/64857051/how-to-push-tag-to-a-branch-in-a-ci/64896748 for a rough idea (should handle authentication). – Rekovni Dec 01 '20 at 12:07