Home > Mobile >  How to resolve conflict while merging branch automatically? in GitLab? do you want a yaml script, a
How to resolve conflict while merging branch automatically? in GitLab? do you want a yaml script, a

Time:04-22

If I merge two branch.It shows,

Merge blocked: merge conflicts must be resolved

If I give resolve conflicts

ENTRYPOINT ["java","-Dspring.profiles.active=**development**","-jar","/app/integration-service.jar"]
ENTRYPOINT ["java","-Dspring.profiles.active=**stage**","-jar","/app/integration-service.jar"]
kind: Deployment
metadata:
  name: integration-app
  namespace: stellacenter-**dev**
  namespace: stellacenter-**stage-uat**
  labels:
    app: integration-app
spec:
kind: Service
metadata:
  name:  integration-service
  namespace: stellacenter-**dev**
  namespace: stellacenter-**stage-uat**
spec:
  type: NodePort
  selector:

It is the easy way to use ours in GitLab and commit to the source branch and done it , but I want to resolve the conflict automatically not manual while merging .Is there any thing to add like rules ? How to do .Please help me to sort out . I've attached yaml script which I'm using.

services:
  - docker:19.03.11-dind
workflow:
  rules:
    - if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH || $CI_COMMIT_BRANCH == "developer" || $CI_COMMIT_BRANCH == "stage"|| ($CI_COMMIT_BRANCH =~ (/^([A-Z]([0-9][-_])?)?SPRINT(([-_][A-Z][0-9])?) /i))
      when: always
    - if: $CI_COMMIT_BRANCH != $CI_DEFAULT_BRANCH || $CI_COMMIT_BRANCH != "developer" || $CI_COMMIT_BRANCH == "stage"|| ($CI_COMMIT_BRANCH !~ (/^([A-Z]([0-9][-_])?)?SPRINT(([-_][A-Z][0-9])?) /i))
      when: never 
stages:
  - build
  - Publish
  - deploy
cache:
  paths:
    - .m2/repository
    - target
build_jar:
  image: maven:3.8.3-jdk-11
  stage: build
  script: 
    - mvn clean install package -DskipTests=true
  artifacts:
    paths:
      - target/*.jar
docker_build:
  stage: Publish
  image: docker:19.03.11
  services:
    - docker:19.03.11-dind
  variables:
    IMAGE_TAG: $CI_REGISTRY_IMAGE:$CI_COMMIT_SHORT_SHA
  script: 
    - docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
    - docker build -t $IMAGE_TAG .
    - docker push $IMAGE_TAG
deploy_dev:
  stage: deploy
  image: stellacenter/aws-helm-kubectl
  before_script:
    - aws configure set aws_access_key_id ${DEV_AWS_ACCESS_KEY_ID}
    - aws configure set aws_secret_access_key ${DEV_AWS_SECRET_ACCESS_KEY}
    - aws configure set region ${DEV_AWS_DEFAULT_REGION}
  script:
    - sed -i "s/<VERSION>/${CI_COMMIT_SHORT_SHA}/g" appointment-service.yml
    - mkdir -p  $HOME/.kube
    - cp $KUBE_CONFIG_DEV $HOME/.kube/config
    - chown $(id -u):$(id -g) $HOME/.kube/config 
    - export KUBECONFIG=$HOME/.kube/config
    - kubectl apply -f appointment-service.yml

CodePudding user response:

There is no automatic way to do this during a merge or MR pipeline. There is also no way to detect a conflict using rules: or similar. You will need to fix the conflict manually.

If you had a way (e.g. a script) to reliably resolve a conflict through a series of repeatable commands, you might be able to automate that by using a CICD job.

For example, you might use the $CI_OPEN_MERGE_REQUESTS or $CI_MERGE_REQUEST_IID to find the open merge request, then use the merge requests API to determine if a conflict exists, then if a conflict exists, take some actions to fix the conflict, then push the fixes to the source branch.

Example:

fix-conflicts:
  stage: .pre # run before all other stages
  rules:
    - if: '$CI_MERGE_REQUEST_IID'
      
  script:
    # use the MR API to detect if there is a conflict. You implement this script.
    # if no conflicts exist (nonzero script exit) - exit 0 for the job
    - ./does-mr-conflict-exist.sh $CI_MERGE_REQUEST_IID || exit 0
    # you implement this script to fix the conflict
    - ./fix-conflicts.sh
    - git push -u origin "$CI_MERGE_REQUEST_SOURCE_BRANCH_NAME"
    - exit 1  # optional - stop the pipeline (a new one will be created from push)
  • Related