skip to Main Content

I want to evaluate in my gitlab_ci pipeline if the current java project is to build with a SNAPSHOT dependency inside the maven pom.xml:

Like so: grep -q "SNAPSHOt" pom.xml && echo 1

Question: how could I integrate this into a ci pipeline so that the pipeline does not even execute if this condition is true?

gitlab_ci.yml:

image: docker:20
build:
  stage: build
  script:
    - mvn package...

Where would I add that sort of condition check, and how could I then let the full job fail?

2

Answers


  1. Chosen as BEST ANSWER
    before_script:
      - grep -q "SNAPSHOT" pom.xml && exit 1
    

    1. If you want the pipeline to run only based on some condition you can use rules.
    2. if you want the pipeline to run and then fail when some condition is
      not satisfied you can just check the condition in script and then
      use exit some_non_zero number.

    eg:

    test job:
      stage: test
      script:
        - | 
            if [ 1 == 1 ]
            then
              exit 1
            fi
    

    Here for condition i have used 1==1.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search