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

chore : factorized API URL

parent 82e0c58b
No related branches found
No related tags found
1 merge request!47Draft: TEST_CI_FORK_DO_NOT_MERGE
......@@ -11,6 +11,7 @@ build:ubuntu_cpp:
# aidge_core
- DEPENDENCY_NAME="aidge_core"
- DEPENDENCY_JOB="build:ubuntu_cpp"
- API_URL="https://gitlab.eclipse.org/api/v4"
# - !reference [.download_dependency, script]
- apt-get -qq install -y jq
# Check if a branch with the same name exist on the dependency repository
......@@ -47,20 +48,22 @@ build:ubuntu_cpp:
- echo "${CI_PROJECT_NAMESPACE_ID}"
- >
if [[ ! $PULL_FROM_FORK ]]; then # nominal case : we are in the official project
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 "${API_URL}/groups/${CI_PROJECT_NAMESPACE_ID}/projects?search=${DEPENDENCY_NAME}" | jq -r '.[0].id')
else # case for fork
echo "Retrieving build_artifacts from user' forked project."
DEPENDENCY_ID=$(curl --header "PRIVATE_TOKEN: $CI_JOB_TOKEN" "https://gitlab.eclipse.org/api/v4/users/${CI_PROJECT_NAMESPACE_ID}/projects?search=${DEPENDENCY_NAME}" | jq -r '.[0].id')
USER=$(curl --header "PRIVATE_TOKEN: $CI_JOB_TOKEN" "${API_URL}/users" | jq .)
USER_ID=$(curl --header "PRIVATE_TOKEN: $CI_JOB_TOKEN" "${API_URL}/users" | jq -r '.[0].id')
DEPENDENCY_ID=$(curl --header "PRIVATE_TOKEN: $CI_JOB_TOKEN" "${API_URL}/users/${CI_PROJECT_NAMESPACE_ID}/projects?search=${DEPENDENCY_NAME}" | jq -r '.[0].id')
fi
# Retrieve latest successful $DEPENDENCY_JOB $BRANCH_TO_PULL
- PIPELINES=$(curl -s --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")
- PIPELINES=$(curl -s --header "PRIVATE_TOKEN:$CI_JOB_TOKEN" "${API_URL}/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 -s --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")))')
JOBS=$(curl -s --header "PRIVATE_TOKEN: $CI_JOB_TOKEN" "${API_URL}/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
......@@ -74,8 +77,8 @@ build:ubuntu_cpp:
fi
- set +x
- 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"
- echo "curling from \"${API_URL}/projects/$DEPENDENCY_ID/jobs/$JOB_ID/artifacts\""
- curl --location --output build_artifacts.zip --header "PRIVATE_TOKEN:$CI_JOB_TOKEN" "${API_URL}/projects/$DEPENDENCY_ID/jobs/$JOB_ID/artifacts"
- unzip -q -o build_artifacts.zip -d .
- rm -rf build_cpp
......
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