From db1cabc14f7a2d189793d54a3312b17d0cf4e86b Mon Sep 17 00:00:00 2001 From: cmoineau <cyril.moineau@cea.fr> Date: Wed, 31 Jan 2024 16:16:15 +0000 Subject: [PATCH] Update script to handle MR on complex cases. --- .gitlab/ci/shared_script.gitlab-ci.yml | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/.gitlab/ci/shared_script.gitlab-ci.yml b/.gitlab/ci/shared_script.gitlab-ci.yml index 97865b9..0056204 100644 --- a/.gitlab/ci/shared_script.gitlab-ci.yml +++ b/.gitlab/ci/shared_script.gitlab-ci.yml @@ -1,14 +1,23 @@ .download_dependency: + # Note: + # For this script to work you need to define teh following variables + # - DEPENDENCY_NAME: Name of the dependency project + # - DEPENDENCY_JOB: Name of the dependency job from which you want to pull artifacts script: - DEFAULT_BRANCH="dev" # Check if a branch with the same name exist on the dependance repository - - RESPONSE_CODE=$(curl -s -o /dev/null -w "%{http_code}" "https://gitlab.eclipse.org/eclipse/aidge/$DEPENDENCY_NAME/-/tree/$CI_COMMIT_REF_NAME") - > if [ "$CI_MERGE_REQUEST_ID" ]; then - # Pulling from target branch - echo "Pull from ${$CI_MERGE_REQUEST_TARGET_BRANCH_NAME}" - curl --location --output build_artifacts.zip "https://gitlab.eclipse.org/api/v4/projects/$CI_PROJECT_ID/jobs/artifacts/$CI_MERGE_REQUEST_TARGET_BRANCH_NAME/download?job=$JOB" - elif [ "$RESPONSE_CODE" -eq 404 ]; then + if [ $(curl -s -o /dev/null -w "%{http_code}" "https://gitlab.eclipse.org/eclipse/aidge/$CI_MERGE_REQUEST_TARGET_BRANCH_NAME/-/tree/$CI_COMMIT_REF_NAME") -eq 404 ]; then + echo "Pull from ${DEFAULT_BRANCH}" + curl --location --output build_artifacts.zip "https://gitlab.eclipse.org/api/v4/projects/$CI_PROJECT_ID/jobs/artifacts/$DEFAULT_BRANCH/download?job=$JOB" + else + # Pulling from target branch + echo "Pull from ${CI_MERGE_REQUEST_TARGET_BRANCH_NAME}" + curl --location --output build_artifacts.zip "https://gitlab.eclipse.org/api/v4/projects/$CI_PROJECT_ID/jobs/artifacts/$CI_MERGE_REQUEST_TARGET_BRANCH_NAME/download?job=$JOB" + fi + + elif [ $(curl -s -o /dev/null -w "%{http_code}" "https://gitlab.eclipse.org/eclipse/aidge/$DEPENDENCY_NAME/-/tree/$CI_COMMIT_REF_NAME") -eq 404 ]; then echo "Pull from ${DEFAULT_BRANCH}" curl --location --output build_artifacts.zip "https://gitlab.eclipse.org/api/v4/projects/$CI_PROJECT_ID/jobs/artifacts/$DEFAULT_BRANCH/download?job=$JOB" else -- GitLab