diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 4f3d9a0f161c2a14c24a0d3f0e8b663197c2063e..0429e2b2e8a95b002dbe4e41d990d4ad8fdcf36e 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -145,12 +145,12 @@ deploy-release: # which builds model with the new version of VIPSCommon. This pipeline fails if model build fails. verify_model_ALTERNARIA: - image: registry.gitlab.com/finestructure/pipeline-trigger + image: eclipse-temurin:17.0.9_9-jdk-jammy stage: models-1 - before_script: [] + before_script: + - apt-get update && apt-get install -y jq curl script: - - echo "trigger -h gitlab.nibio.no -a [MASKED] -p [MASKED] -t $MAIN_BRANCH $ALTERNARIA_PROJECT_ID -e VERSION=$VERSION -e PURPOSE=\"verify\"" - - trigger -h gitlab.nibio.no -a "$CICD_API_TOKEN" -p "$ACCESS_TOKEN_ALTERNARIA" -t $MAIN_BRANCH $ALTERNARIA_PROJECT_ID -e VERSION=$VERSION -e PURPOSE="verify" + - ./trigger_model_verification.sh "$ALTERNARIA_PROJECT_ID" "$MAIN_BRANCH" "$VERSION" "verify" tags: - java dependencies: diff --git a/trigger_model_verification.sh b/trigger_model_verification.sh new file mode 100755 index 0000000000000000000000000000000000000000..a25196f5ff01c1630bd0dc9d78fb5f351f262901 --- /dev/null +++ b/trigger_model_verification.sh @@ -0,0 +1,72 @@ +#!/bin/bash +set -euo pipefail + +echo "Triggering ALTERNARIA verification pipeline via API..." + +curl --fail --silent --show-error --request POST \ + --header "JOB-TOKEN: $CI_JOB_TOKEN" \ + --form ref="${MAIN_BRANCH}" \ + --form "variables[VERSION]=${VERSION}" \ + --form "variables[PURPOSE]=verify" \ + "https://gitlab.juba.no/api/v4/projects/${ALTERNARIA_PROJECT_ID}/trigger/pipeline" + + +#!/bin/bash +set -euo pipefail + +# Usage: +# ./trigger_model_verification.sh <project_id> <ref> <version> <purpose> + +PROJECT_ID="$1" +REF="$2" +VERSION="$3" +PURPOSE="$4" + +API_URL="https://gitlab.nibio.no/api/v4" + +echo "Triggering pipeline for project $PROJECT_ID on ref '$REF'..." + +# Trigger the pipeline +PIPELINE_JSON=$(curl --fail --silent --show-error --request POST \ + --header "JOB-TOKEN: $CI_JOB_TOKEN" \ + --form ref="$REF" \ + --form "variables[VERSION]=$VERSION" \ + --form "variables[PURPOSE]=$PURPOSE" \ + "$API_URL/projects/${PROJECT_ID}/trigger/pipeline") + +# Extract pipeline ID +PIPELINE_ID=$(echo "$PIPELINE_JSON" | jq -r '.id') + +if [[ -z "$PIPELINE_ID" || "$PIPELINE_ID" == "null" ]]; then + echo "❌ Failed to get pipeline ID from response." + echo "$PIPELINE_JSON" + exit 1 +fi + +echo "✅ Pipeline triggered: ID=$PIPELINE_ID" +echo "🔄 Waiting for pipeline to complete..." + +# Poll for status +while true; do + STATUS=$(curl --fail --silent --header "JOB-TOKEN: $CI_JOB_TOKEN" \ + "$API_URL/projects/${PROJECT_ID}/pipelines/${PIPELINE_ID}" | jq -r '.status') + + echo "🔍 Status: $STATUS" + case "$STATUS" in + success) + echo "✅ Downstream pipeline succeeded." + exit 0 + ;; + failed|canceled|skipped|manual) + echo "❌ Downstream pipeline ended with status: $STATUS" + exit 1 + ;; + running|pending) + sleep 5 + ;; + *) + echo "⚠️ Unexpected status: $STATUS" + exit 1 + ;; + esac +done