diff --git a/.gitlab/ci/build.gitlab-ci.yml b/.gitlab/ci/build.gitlab-ci.yml index 6a1d924fe4ae31372e321034f273e93be0bbd1a3..609932195e2b3bafe83a758a02f43fd25ecf1a80 100644 --- a/.gitlab/ci/build.gitlab-ci.yml +++ b/.gitlab/ci/build.gitlab-ci.yml @@ -45,8 +45,21 @@ build:ubuntu_cpp: # Retrieve $DEPENDENCY_JOB from latest pipeline of $BRANCH_TO_PULL, independant from its success or failure DEPENDENCY_ID=$(curl --header "PRIVATE_TOKEN: $CI_JOB_TOKEN" "https://gitlab.eclipse.org/api/v4/users/${USER_ID}/projects?search=${DEPENDENCY_NAME}" | jq -r '.[0].id') - PIPELINE_ID=$(curl --header "PRIVATE_TOKEN: $CI_JOB_TOKEN" "https://gitlab.eclipse.org/api/v4/projects/$DEPENDENCY_ID/pipelines?ref=${BRANCH_TO_PULL}&order_by=updated_at&sort=desc" | jq -r ".[0].id") - JOB_ID=$(curl --header "PRIVATE_TOKEN: $CI_JOB_TOKEN" "https://gitlab.eclipse.org/api/v4/projects/$DEPENDENCY_ID/pipelines/$PIPELINE_ID/jobs" | jq --arg job_name "$DEPENDENCY_JOB" 'map(select(.name == $job_name)) | .[0].id') + PIPELINES=$(curl --header "PRIVATE_TOKEN: $CI_JOB_TOKEN" "https://gitlab.eclipse.org/api/v4/projects/$DEPENDENCY_ID/pipelines?ref=${BRANCH_TO_PULL}&order_by=updated_at&sort=desc") + JOB_ID=-1 + # handle case where there is no branch with the same name + for i in $(seq 0 $(jq length <<< "$PIPELINES")) + do + PIPELINE_ID=$(jq --argjson idx $i '.[$idx].id' <<< $PIPELINES) + JOBS=$(curl --header "PRIVATE_TOKEN: $CI_JOB_TOKEN" "https://gitlab.eclipse.org/api/v4/projects/$DEPENDENCY_ID/pipelines/$PIPELINE_ID/jobs" | jq --arg job_name "$DEPENDENCY_JOB" 'map(select((.name == $job_name) and (.status == "success")))') + if [[ $(jq '. | length' <<< $JOBS) > 0 ]]; then + JOB_ID=$(jq '.[0].id' <<< $JOBS) + break + fi + done + if( $JOB_ID == -1 ) ; then + echo "ERROR : no successful job \"$DEPENDENCY_JOB\" found in branch \"$BRANCH_TO_PULL\" for project \"$DEPENDENCY_NAME\"" + fi echo "curling from \"https://gitlab.eclipse.org/api/v4/projects/$DEPENDENCY_ID/jobs/$JOB_ID/artifacts\"" curl --location --output build_artifacts.zip --header "PRIVATE_TOKEN: $CI_JOB_TOKEN" "https://gitlab.eclipse.org/api/v4/projects/$DEPENDENCY_ID/jobs/$JOB_ID/artifacts" set +x