Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
gitlab_shared_files
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Deploy
Releases
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Eclipse Projects
aidge
gitlab_shared_files
Commits
5a194f66
Commit
5a194f66
authored
1 year ago
by
Grégoire Kubler
Browse files
Options
Downloads
Patches
Plain Diff
feat : automated retrieval of USER_ID
parent
56235add
No related branches found
Branches containing commit
No related tags found
1 merge request
!2
Fix/ci fork exec
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
.gitlab/ci/shared_script.gitlab-ci.yml
+20
-13
20 additions, 13 deletions
.gitlab/ci/shared_script.gitlab-ci.yml
with
20 additions
and
13 deletions
.gitlab/ci/shared_script.gitlab-ci.yml
+
20
−
13
View file @
5a194f66
...
...
@@ -5,12 +5,15 @@
# - DEPENDENCY_JOB: Name of the dependency job from which you want to pull artifacts
script
:
-
apt-get -qq install -y jq
-
GITLAB_ECLIPSE_URL="https://gitlab.eclipse.org/"
-
API_URL="https://gitlab.eclipse.org/api/v4"
# 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 # 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
if [ $(curl -s -o /dev/null -w "%{http_code}" "
$GITLAB_ECLIPSE_URL
/eclipse/aidge/$DEPENDENCY_NAME/-/tree/$CI_MERGE_REQUEST_TARGET_BRANCH_NAME") -eq 404 ]; then
echo "Pull from default"
else
# Pulling from target branch
...
...
@@ -18,11 +21,13 @@
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
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
# checking if given branch exist on official repo or on fork
RETURN_HTTP_CODE_OFFICIAL_REPO=$(curl -s -o /dev/null -w "%{http_code}" "$GITLAB_ECLIPSE_URL/eclipse/$CI_PROJECT_NAMESPACE/$DEPENDENCY_NAME/-/tree/$CI_COMMIT_REF_NAME")
RETURN_HTTP_CODE_FORK=$(curl -s -o /dev/null -w "%{http_code}" "$GITLAB_ECLIPSE_URL/$CI_PROJECT_NAMESPACE/$DEPENDENCY_NAME/-/tree/$CI_COMMIT_REF_NAME")
if [[ $RETURN_HTTP_CODE_OFFICIAL_REPO -ne 302 && $RETURN_HTTP_CODE_OFFICIAL_REPO -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 && $(curl -s -o /dev/null -w "%{http_code}" "https://gitlab.eclipse.org/hrouis/$DEPENDENCY_NAME/-/tree/$CI_COMMIT_REF_NAME")
-ne 302 ]]; then
elif [[ $
RETURN_HTTP_CODE_FORK -ne 302 && $RETURN_HTTP_CODE_FORK
-ne 302 ]]; then
PULL_FROM_FORK=TRUE
BRANCH_TO_PULL=$CI_COMMIT_REF_NAME
else
...
...
@@ -31,23 +36,25 @@
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')
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
hrouis
' forked project."
USER_ID=
17216
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')
echo "Retrieving build_artifacts from
user
' forked project."
USER_ID=
$(curl "${API_URL}/users?username=${CI_PROJECT_ROOT_NAMESPACE}" | jq -r '.[0].id')
DEPENDENCY_ID=$(curl
"${API_URL}
/users/${USER_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")
# Retrieve latest successful $DEPENDENCY_JOB
from
$BRANCH_TO_PULL
-
PIPELINES=$(curl -s
"${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
"${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
...
...
@@ -60,8 +67,8 @@
echo "Successful job \"$DEPENDENCY_JOB\" found in branch \"$BRANCH_TO_PULL\" for project \"$DEPENDENCY_NAME\""
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"
-
echo "curling from \"
${API_URL}
/projects/$DEPENDENCY_ID/jobs/$JOB_ID/artifacts\""
-
curl --location --output build_artifacts.zip
"${API_URL}
/projects/$DEPENDENCY_ID/jobs/$JOB_ID/artifacts"
-
unzip -q -o build_artifacts.zip -d .
-
rm -rf build_cpp
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment