skip to Main Content

I have GitLab CI config like this

image: hmmmk/androidbuildenv-jdk17-api33:latest

stages:
  - build
  - deploy

# TODO: replace with assembleRelease
build_main:
  stage: build
  script:
    - ./gradlew assembleDebug
  artifacts:
    paths:
      - app/build/outputs/
  rules:
    - if: '$CI_MERGE_REQUEST_TARGET_BRANCH_NAME == "main"'
      when: always
    - if: '$CI_COMMIT_REF_NAME == "main"'
      when: never

build_develop:
  stage: build
  script:
    - ./gradlew assembleDebug
  artifacts:
    paths:
      - app/build/outputs/
  rules:
    - if: '$CI_MERGE_REQUEST_TARGET_BRANCH_NAME == "develop"'
      when: always
    - if: '$CI_COMMIT_REF_NAME == "develop"'
      when: never

deploy_develop_telegram:
  stage: deploy
  script:
    - apk_file=$(find app/build/outputs/ -name "*.apk" | head -n 1)
    - echo "Sending $apk_file to Telegram..."
    - curl -F chat_id="-1" -F document=@"$apk_file" -F caption="New APK build from CI" https://api.telegram.org/botid/sendDocument
  needs: ["build_develop"]

And the thing is that deploy_develop_telegram is never called after build_develop successfully finishes. I don’t even see deploy_develop_telegram in GitLab dashboard. I tried different approaches also with rules and needs but nothing seems to be working. No error messages, nothing, looks like GitLab just ignores this job.

What am I doing wrong?

2

Answers


  1. Chosen as BEST ANSWER

    The issue is related to job rules. Somehow, GitLab CI ignores dependant jobs if their rules block doesn't match the block from the job they depend on. So solution for this will be just adding:

    rules:
        - if: '$CI_MERGE_REQUEST_TARGET_BRANCH_NAME == "develop"'
          when: always
    

    to deploy_develop_telegram job.

    The only problem is that I don't understand the reason behind this, cause for me, it should not work like this, because needs already defines the actual "rule" for this job. If somebody can explain this better, please leave a comment.


  2. In what workflow do you expect this pipeline to run successfully ?

    To me the rules for build_main and build_developare preventingdeploy_develop_telegram` from running.

    Furthermore, you repeat both build jobs with no visible differences in the job’s script. Perhaps you should move the rules in deploy_develop_telegram job to prevent it from running instead.

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