diff --git a/.gitlab/ci/shared_script.gitlab-ci.yml b/.gitlab/ci/shared_script.gitlab-ci.yml index f44d3088ac81e3c21f3140e9829545bbcaa969b6..4894ecfeab426947dab813853eccd5d41e22b21c 100644 --- a/.gitlab/ci/shared_script.gitlab-ci.yml +++ b/.gitlab/ci/shared_script.gitlab-ci.yml @@ -4,25 +4,26 @@ # - 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" + -BRANCH_TO_PULL="dev" # default branch # Check if a branch with the same name exist on the dependance repository - > if [ "$CI_MERGE_REQUEST_ID" ]; 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 + 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" + else + # Pulling from target branch + echo "Pull from ${CI_MERGE_REQUEST_TARGET_BRANCH_NAME}" + BRANCH_TO_PULL=${CI_MERGE_REQUEST_TARGET_BRANCH_NAME} + 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" + echo "Pull from default" else - # Pulling from branch with same name - echo "Pull from ${CI_COMMIT_REF_NAME}" - curl --location --output build_artifacts.zip "https://gitlab.eclipse.org/api/v4/projects/$CI_PROJECT_ID/jobs/artifacts/$CI_COMMIT_REF_NAME/download?job=$JOB" + # Pulling from branch with same name + echo "Pull from branch name" + BRANCH_TO_PULL=${CI_COMMIT_REF_NAME} fi + - echo "curling from https://gitlab.eclipse.org/api/v4/projects/$CI_PROJECT_ID/jobs/artifacts/$BRANCH_TO_PULL/download?job=$DEPENDENCY_JOB" + - curl -f --location --output build_artifacts.zip "https://gitlab.eclipse.org/api/v4/projects/$CI_PROJECT_ID/jobs/artifacts/$BRANCH_TO_PULL/download?job=$DEPENDENCY_JOB" - unzip -o build_artifacts.zip -d . - rm -rf build_cpp