diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 9efdd37b1853046783427d71187fc473c26900da..3940869ca6436807772c434758b10727153498f3 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -24,19 +24,18 @@ build_dev: # Build the image with the SHA-specific tag - docker build --build-arg SERVER_URL="https://docs.dev.unhide.helmholtz-metadaten.de/" --build-arg NODE_ENV=dev -t "$IMAGE_NAME_SHA" . - # Tag the image as 'develop:latest' - - docker tag "$IMAGE_NAME_SHA" "$IMAGE_NAME" - - # Push both tags - - docker push "$IMAGE_NAME_SHA" - - docker push "$IMAGE_NAME" - - # Save IMAGE_NAME_SHA to a file - - echo "$IMAGE_NAME_SHA" > image_name_sha.txt + # Only push the image if it's a direct commit to `dev` + - | + if [ "$CI_COMMIT_BRANCH" == "dev" ] && [ "$CI_PIPELINE_SOURCE" == "push" ]; then + docker tag "$IMAGE_NAME_SHA" "$IMAGE_NAME" + docker push "$IMAGE_NAME_SHA" + docker push "$IMAGE_NAME" + echo "$IMAGE_NAME_SHA" > image_name_sha.txt + fi artifacts: paths: - image_name_sha.txt - expire_in: 1 hour # Optional: Set how long the artifact is kept + expire_in: 1 hour rules: - if: '$CI_COMMIT_BRANCH == "dev"' exists: @@ -50,7 +49,7 @@ update_manifests_dev: variables: MANIFESTS_REPO: 'https://codebase.helmholtz.cloud/hmc/hmc-public/unhide/development/devops/documentation-manifests.git' dependencies: - - build_dev # Ensure the artifact is downloaded from the build_dev job + - build_dev before_script: - git config --global user.name "GitLab CI" - git config --global user.email "ci@backend.manifests" @@ -74,7 +73,6 @@ update_manifests_dev: - git commit -m "Update image to $IMAGE_NAME_SHA" - git push artifacts: - expire_in: 1 hour # Optional: Set artifact expiration for the sync job + expire_in: 1 hour rules: - - if: '$CI_COMMIT_BRANCH == "dev"' - - if: '$CI_MERGE_REQUEST_TARGET_BRANCH_NAME == "dev"' + - if: '$CI_COMMIT_BRANCH == "dev" && $CI_PIPELINE_SOURCE == "push"'