2

I am trying to achieve the the below flow possible using gitlab CI. As I will be having multiple branches such as(dev-*, release- *, feature- *) with the will to manage them. Initially I just want to know if I can achieve this flow. I tried using an "if" statement in gitlabCI but as I have just started using it, I am not able to create and understand the features provided by gitlab. The desire flow in gitlabCI:

if (MR from feature* to Dev OR MR from feature* to release)
{
  echo "Unit Testing";
  echo "Code quality analysis";
}
if (feature* MERGE to Dev)  
{
  echo "Build Docker image with tag $Build_ID";
}
if (feature* MERGE to Release:<release_version>)
{
  echo "Build docker image with $release_version"
}

MR refer to merge request.

feature, dev, release are branches.

1 Answer 1

2

I wrote a complete answer on another post, which you can check. But in summary, you can use workflow and rules to control the execution flow of the pipeline and stages. You can read more about them Gitlab CI workflow and Gitlab CI rules page.

In this case, you can use rules like the following example. The runner will trigger the test stage only if one of the following if statements evaluated to true.

test:
  stage: test
  script:
    - echo "Unit Testing";
    - echo "Code quality analysis";
  rules:
    if: '$CI_MERGE_REQUEST_SOURCE_BRANCH_NAME =~ /^feature/ && $CI_MERGE_REQUEST_TARGET_BRANCH_NAME == dev' # Merge request from feature to dev
    if: '$CI_MERGE_REQUEST_SOURCE_BRANCH_NAME =~ /^feature/ && $CI_MERGE_REQUEST_TARGET_BRANCH_NAME == release' # Merge request from feature to release
...
Sign up to request clarification or add additional context in comments.

1 Comment

If my answer was helpful, please upvote it. Thanks.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.