Skip to content
Snippets Groups Projects
Commit 8c66773b authored by Grégoire Kubler's avatar Grégoire Kubler
Browse files

feat : refactor to unify artifact pull processes

parent e2e0244f
No related branches found
No related tags found
1 merge request!47Draft: TEST_CI_FORK_DO_NOT_MERGE
...@@ -36,35 +36,34 @@ build:ubuntu_cpp: ...@@ -36,35 +36,34 @@ build:ubuntu_cpp:
- > - >
if [ "$(curl -s -o /dev/null -w "%{http_code}" "https://gitlab.eclipse.org/api/v4/groups/${CI_PROJECT_NAMESPACE_ID}")" != "404" ]; then if [ "$(curl -s -o /dev/null -w "%{http_code}" "https://gitlab.eclipse.org/api/v4/groups/${CI_PROJECT_NAMESPACE_ID}")" != "404" ]; then
DEPENDENCY_ID=$(curl "https://gitlab.eclipse.org/api/v4/groups/${CI_PROJECT_NAMESPACE_ID}/projects?search=${DEPENDENCY_NAME}" | jq -r '.[0].id') DEPENDENCY_ID=$(curl "https://gitlab.eclipse.org/api/v4/groups/${CI_PROJECT_NAMESPACE_ID}/projects?search=${DEPENDENCY_NAME}" | jq -r '.[0].id')
echo "curling from \"https://gitlab.eclipse.org/api/v4/projects/$DEPENDENCY_ID/jobs/artifacts/$BRANCH_TO_PULL/download?job=$DEPENDENCY_JOB\""
curl -f --location --output build_artifacts.zip "https://gitlab.eclipse.org/api/v4/projects/$DEPENDENCY_ID/jobs/artifacts/$BRANCH_TO_PULL/download?job=$DEPENDENCY_JOB"
else # case for fork else # case for fork
set -x
echo "Retrieving build_artifacts from hrouis' forked project." echo "Retrieving build_artifacts from hrouis' forked project."
USER_ID=17216 USER_ID=17216
# 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') 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')
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") fi
JOB_ID=-1
# handle case where there is no branch with the same name # Retrieve latest successful $DEPENDENCY_JOB $BRANCH_TO_PULL
for i in $(seq 0 $(jq length <<< "$PIPELINES")) 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")
do JOB_ID=-1
PIPELINE_ID=$(jq --argjson idx $i '.[$idx].id' <<< $PIPELINES) # handle case where there is no branch with the same name
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")))') for i in $(seq 0 $(jq length <<< "$PIPELINES"))
if [[ $(jq '. | length' <<< $JOBS) > 0 ]]; then do
JOB_ID=$(jq '.[0].id' <<< $JOBS) PIPELINE_ID=$(jq --argjson idx $i '.[$idx].id' <<< $PIPELINES)
break 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")))')
fi if [[ $(jq '. | length' <<< $JOBS) > 0 ]]; then
done JOB_ID=$(jq '.[0].id' <<< $JOBS)
if( $JOB_ID == -1 ) ; then break
echo "ERROR : no successful job \"$DEPENDENCY_JOB\" found in branch \"$BRANCH_TO_PULL\" for project \"$DEPENDENCY_NAME\""
fi fi
echo "curling from \"https://gitlab.eclipse.org/api/v4/projects/$DEPENDENCY_ID/jobs/$JOB_ID/artifacts\"" done
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" if( $JOB_ID == -1 ) ; then
set +x echo "ERROR : no successful job \"$DEPENDENCY_JOB\" found in branch \"$BRANCH_TO_PULL\" for project \"$DEPENDENCY_NAME\""
else
echo "Successful job \"$DEPENDENCY_JOB\" found in branch \"$BRANCH_TO_PULL\" for project \"$DEPENDENCY_NAME\""
fi 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"
- unzip -q -o build_artifacts.zip -d . - unzip -q -o build_artifacts.zip -d .
- rm -rf build_cpp - rm -rf build_cpp
# end !reference[] # end !reference[]
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment