Skip to main content

Command Palette

Search for a command to run...

Gitlab Ancestor Check Branches

Published
2 min read
Gitlab Ancestor Check Branches

####How to ensure the child branches are always up-to-date with their parent one

Alt Text

  • From the example above, when feature branch is merged to develop branch then dev branch need to be updated to get latest code from develop so it will get no conflict or perform test with integration code when it's merged back to develop. Same behavior for integrate branch

  • Here is the .pre job in gitlab pipeline to ensure this ``` stages:

    • build
    • deploy

ancestor_develop: stage: .pre script:

- git merge-base --is-ancestor origin/develop HEAD || ( echo "Branch is not an ancestor of develop"; /bin/false )

only: refs:

  - dev
  - feature
  - integrate

tags:

- ancestor-check

compile_code: stage: build script:

- echo build image

only: refs:

  - dev
  - feature
  - integrate

tags:

- runner-build

deploy_test: stage: deploy script:

- echo Deploy to test env

only: refs:

  - dev
  - feature
  - integrate

tags:

- runner-deploy

```

  • .pre is highest priority stage in gitlab pipeline, it must be passed in order to continue other stages (build and deploy)
  • Ref: git-merge-base(1) Manual Page

--is-ancestor

Check if the first is an ancestor of the second , and exit with status 0 if true, or with status 1 if not. Errors are signaled by a non-zero status that is not

More from this blog

V

Vu Dao

102 posts

🚀 AWSome Devops | AWS Community Builder | AWS SA || ☁️ SimflexCloud ☁️