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

chore : re added 404 error code for safety

parent c8f90375
No related branches found
No related tags found
1 merge request!47Draft: TEST_CI_FORK_DO_NOT_MERGE
......@@ -13,11 +13,10 @@ build:ubuntu_cpp:
- DEPENDENCY_JOB="build:ubuntu_cpp"
# - !reference [.download_dependency, script]
- apt-get -qq install -y jq
# Check if a branch with the same name exist on the dependance repository
# Check if a branch with the same name exist on the dependency repository
- BRANCH_TO_PULL="dev" # default branch
- set -x
- >
if [ "$CI_MERGE_REQUEST_ID" ]; then
if [ "$CI_MERGE_REQUEST_ID" ]; then # CASE MERGE REQUEST
echo "Merge request pipeline detected"
if [ $(curl -s -o /dev/null -w "%{http_code}" "https://gitlab.eclipse.org/eclipse/aidge/$DEPENDENCY_NAME/-/tree/$CI_MERGE_REQUEST_TARGET_BRANCH_NAME") -eq 404 ]; then
echo "Pull from default"
......@@ -26,19 +25,20 @@ build:ubuntu_cpp:
echo "Pull from ${CI_MERGE_REQUEST_TARGET_BRANCH_NAME}"
BRANCH_TO_PULL=${CI_MERGE_REQUEST_TARGET_BRANCH_NAME}
fi
else # CASE CASUAL COMMIT
# checking if given branch exist on official repo or on fork
elif [[ $(curl -s -o /dev/null -w "%{http_code}" "https://gitlab.eclipse.org/eclipse/aidge/$DEPENDENCY_NAME/-/tree/$CI_COMMIT_REF_NAME") -ne 302 ]]; then
if [[ [ $(curl -s -o /dev/null -w "%{http_code}" "https://gitlab.eclipse.org/eclipse/aidge/$DEPENDENCY_NAME/-/tree/$CI_COMMIT_REF_NAME") -ne 302 ] && [ $(curl -s -o /dev/null -w "%{http_code}" "https://gitlab.eclipse.org/eclipse/aidge/$DEPENDENCY_NAME/-/tree/$CI_COMMIT_REF_NAME") -ne 404 ]]]; then
PULL_FROM_FORK=FALSE
BRANCH_TO_PULL=$CI_COMMIT_REF_NAME
elif [[ $(curl -s -o /dev/null -w "%{http_code}" "https://gitlab.eclipse.org/hrouis/$DEPENDENCY_NAME/-/tree/$CI_COMMIT_REF_NAME") -ne 302 ]]; then
elif [[ [ $(curl -s -o /dev/null -w "%{http_code}" "https://gitlab.eclipse.org/hrouis/$DEPENDENCY_NAME/-/tree/$CI_COMMIT_REF_NAME") -ne 302 ] && [ $(curl -s -o /dev/null -w "%{http_code}" "https://gitlab.eclipse.org/hrouis/$DEPENDENCY_NAME/-/tree/$CI_COMMIT_REF_NAME") -ne 302 ] ]]; then
PULL_FROM_FORK=TRUE
BRANCH_TO_PULL=$CI_COMMIT_REF_NAME
else
PULL_FROM_FORK=FALSE
echo "No branch \"$CI_COMMIT_REF_NAME\" found for \"$DEPENDENCY_NAME\" in official or forked repos."
else
PULL_FROM_FORK=FALSE
echo "No branch \"$CI_COMMIT_REF_NAME\" found for \"$DEPENDENCY_NAME\" in official or forked repos."
fi
fi
- echo "Pulling from branch:\"$BRANCH_TO_PULL\""
- set +x
- >
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')
......@@ -54,14 +54,12 @@ build:ubuntu_cpp:
# handle case where there is no branch with the same name
- >
for i in $(seq 0 $(jq length <<< "$PIPELINES")); do
set -x
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")))')
if [[ $(jq '. | length' <<< $JOBS) > 0 ]]; then
JOB_ID=$(jq '.[0].id' <<< $JOBS)
break
fi
set +x
done
- >
if( $JOB_ID == -1 ) ; then
......@@ -75,7 +73,7 @@ build:ubuntu_cpp:
- unzip -q -o build_artifacts.zip -d .
- rm -rf build_cpp
# end !reference[]
# end !reference[]
# Build current module
......
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