-
Bug
-
Resolution: Unresolved
-
Minor
-
None
-
DEV
i am making call to gitlab via api which runs from the bash script via curl command in it. it is working fine with 2.8.3 version. but its getting stuck when i update plugin.
pasting my bash script below for reference.
#!/bin/bash
- Replace with your GitLab personal access token and project ID
ACCESS_TOKEN="Token"
PROJECT_ID="some number"
- Initialize an empty array to hold all branches
all_branches=()
- Fetch branches page by page
page=1
while :; do
response=$(curl --silent --header "PRIVATE-TOKEN: $ACCESS_TOKEN" "https://gitlab.example.com/api/v4/projects/$PROJECT_ID/repository/branches?per_page=100&page=$page")
branches=$(echo "$response" | jq '.')
- Break the loop if no more branches are returned
if [ "$(echo "$branches" | jq 'length')" -eq 0 ]; then
break
fi
- Append the branches to the all_branches array
all_branches+=("$branches")
- Increment the page number
page=$((page + 1))
done
- Combine all branches into a single JSON array
combined_branches=$(echo "${all_branches[@]}" | jq -s 'add')
- Sort the branches by the commit date and get the latest 20 branch names
echo "$combined_branches" | jq 'sort_by(.commit.committed_date) | reverse | .[:20] | .[].name' | sed 's/"//g'
below is groovy script which runs in background to call bash script
def proc ="/var/lib/jenkins/scripts/gitlab/branches.sh ${PROJECT_ID}".execute()
proc.waitFor()
def output = proc.in.text
def exitcode= proc.exitValue()
def error = proc.err.text
if (error) {
println "Std Err: ${error}"
println "Process exit code: ${exitcode}"
return exitcode
}
return output.tokenize()