Skip to content
Snippets Groups Projects
Commit 26a982a9 authored by Grégoire Kubler's avatar Grégoire Kubler Committed by Grégoire Kubler
Browse files

fix : added missing section in windows:select_jobs to handle case where a tag was created.

parent 015ddfe0
No related branches found
No related tags found
No related merge requests found
...@@ -100,7 +100,6 @@ ...@@ -100,7 +100,6 @@
| map(select(.commit.created_at != null and (.commit.created_at <= $before_date))) | map(select(.commit.created_at != null and (.commit.created_at <= $before_date)))
' <<<"$DEP_TAGS") ' <<<"$DEP_TAGS")
SELECTED_TAG=""
if [[ $(jq length <<<"$TAGS_BEFORE_DATE") != 0 ]]; then if [[ $(jq length <<<"$TAGS_BEFORE_DATE") != 0 ]]; then
BRANCH_TO_PULL=$(jq -r '.[0].name' <<<"$TAGS_BEFORE_DATE") BRANCH_TO_PULL=$(jq -r '.[0].name' <<<"$TAGS_BEFORE_DATE")
echo "Found release : $BRANCH_TO_PULL. Using it as \$BRANCH_TO_PULL." echo "Found release : $BRANCH_TO_PULL. Using it as \$BRANCH_TO_PULL."
...@@ -302,8 +301,7 @@ ...@@ -302,8 +301,7 @@
$DEP_ID=$(Invoke-RestMethod -Uri "$API_URL/users/$USER_ID/projects?search=${DEP_NAME}" -Method Get)[0].id $DEP_ID=$(Invoke-RestMethod -Uri "$API_URL/users/$USER_ID/projects?search=${DEP_NAME}" -Method Get)[0].id
} }
Write-Host "DEP_ID = $DEP_ID" Write-Host "DEP_ID = $DEP_ID"
$DEP_URL="$DEP_API_URL" $DEP_API_URL="$API_URL/projects/$DEP_ID"
###################################################################################################### ######################################################################################################
# Retrieve the branch to pull # Retrieve the branch to pull
...@@ -319,55 +317,58 @@ ...@@ -319,55 +317,58 @@
$BRANCH_TO_PULL=$DEFAULT_BRANCH # default branch to pull $BRANCH_TO_PULL=$DEFAULT_BRANCH # default branch to pull
Write-Host "Choosing a branch to pull dependending if we are in a Non draft merge request or not." Write-Host "Choosing a branch to pull dependending if we are in a Non draft merge request or not."
Write-Host "CI_MERGE_REQUEST_TITLE = $CI_MERGE_REQUEST_TITLE" Write-Host "CI_MERGE_REQUEST_TITLE = $CI_MERGE_REQUEST_TITLE"
Write-Host "CI_COMMIT_TAG = $CI_COMMIT_TAG"
Write-Host "CI_MERGE_REQUEST_TITLE = $CI_MERGE_REQUEST_TITLE"
################################ ################################
# CASE NON DRAFT MERGE REQUEST # CASE NON DRAFT MERGE REQUEST
if ( "$CI_MERGE_REQUEST_ID" -and ! ("$CI_MERGE_REQUEST_TITLE" -match 'Draft.*') ) { # case we are in a merge request if ( "$CI_MERGE_REQUEST_ID" -and ! ("$CI_MERGE_REQUEST_TITLE" -match 'Draft.*') ) { # case we are in a merge request
# If the MR is not in draft: pulling from target branch (if exists otherwise dev) # If the MR is not in draft: pulling from target branch (if exists otherwise dev)
Write-Host "Retrieving branches of $DEP_NAME $DEP_API_URL/repository/branches?per_page=100" Write-Host "Retrieving branches of $DEP_NAME $DEP_API_URL/repository/branches?per_page=100"
$DEP_BRANCHES=$($(Invoke-RestMethod -Uri "$DEP_API_URL/repository/branches?per_page=100" -Method Get) | Select-Object name) $DEP_BRANCHES=$($(Invoke-RestMethod -Uri "$DEP_API_URL/repository/branches?per_page=100" -Method Get) | Select-Object name)
Write-Host "Found $($DEP_BRANCHES.Count) branches." Write-Host "Found $($DEP_BRANCHES.Count) branches."
Write-Host "$($DEP_BRANCHES | Out-String)" Write-Host "$($DEP_BRANCHES | Out-String)"
Write-Host "NON DRAFT MERGE REQUEST Pipeline detected : Pulling from CI_MERGE_REQUEST_TARGET_BRANCH_NAME : $CI_MERGE_REQUEST_TARGET_BRANCH_NAME." Write-Host "NON DRAFT MERGE REQUEST Pipeline detected : Pulling from CI_MERGE_REQUEST_TARGET_BRANCH_NAME : $CI_MERGE_REQUEST_TARGET_BRANCH_NAME."
Write-Host "Checking if CI_MERGE_REQUEST_TARGET_BRANCH_NAME "$CI_MERGE_REQUEST_TARGET_BRANCH_NAME" branch exists, otherwise pull from default." Write-Host "Checking if CI_MERGE_REQUEST_TARGET_BRANCH_NAME "$CI_MERGE_REQUEST_TARGET_BRANCH_NAME" branch exists, otherwise pull from default."
$FILTERED_BRANCHES=@($DEP_BRANCHES | Where-Object { $_.name -eq "$CI_MERGE_REQUEST_TARGET_BRANCH_NAME"}) $FILTERED_BRANCHES=@($DEP_BRANCHES | Where-Object { $_.name -eq "$CI_MERGE_REQUEST_TARGET_BRANCH_NAME"})
if ( ($FILTERED_BRANCHES.Count) -gt 0){
Write-Host "Found MR target branch in $DEP_NAME." if ( ($FILTERED_BRANCHES.Count) -gt 0){
$BRANCH_TO_PULL=$CI_MERGE_REQUEST_TARGET_BRANCH_NAME Write-Host "Found MR target branch in $DEP_NAME."
Write-Host "Pulling from merge request target branch $CI_MERGE_REQUEST_TARGET_BRANCH_NAME" $BRANCH_TO_PULL=$CI_MERGE_REQUEST_TARGET_BRANCH_NAME
} else { Write-Host "Pulling from merge request target branch $CI_MERGE_REQUEST_TARGET_BRANCH_NAME"
Write-Host "Branch $CI_MERGE_REQUEST_TARGET_BRANCH_NAME not found on repo $DEP_NAME." } else {
Write-Host "Pulling from default branch." Write-Host "Branch $CI_MERGE_REQUEST_TARGET_BRANCH_NAME not found on repo $DEP_NAME."
} Write-Host "Pulling from default branch."
}
###################################### ######################################
# CASE WHERE A COMMIT TAG IS CREATED # CASE WHERE A COMMIT TAG IS CREATED
} else if ( "$CI_COMMIT_TAG" ) { } elseif ( "$CI_COMMIT_TAG" ) {
$REPO_CURR_TAG_DATE=$($(Invoke-RestMethod -Uri "$DEP_API_URL/repository/tags/$CI_COMMIT_TAG" -Method Get) | Select-Object commit.created_at) Write-Host "Rretrieving the creation_date of the commit the tag has been created from $DEP_API_URL/repository/tags/$CI_COMMIT_TAG"
# PROJECT_CURR_TAG_DATE=$(jq '.commit.created_at' <<<$(curl -s "$API_URL/projects/$CI_PROJECT_ID/repository/tags/$CI_COMMIT_TAG")) $REPO_CURR_TAG_DATE=$($(Invoke-RestMethod -Uri "$DEP_API_URL/repository/tags/$CI_COMMIT_TAG" -Method Get).commit.created_at)
Write-Host "REPO_CURR_TAG_DATE = $REPO_CURR_TAG_DATE"
Write-Host "Looking for latest release in $DEP_NAME before $CI_COMMIT_TAG was released on project $CI_PROJECT_NAME." Write-Host "Looking for latest release in $DEP_NAME before $CI_COMMIT_TAG was released on project $CI_PROJECT_NAME."
$DEP_TAGS_BEFORE_DATE=$($(Invoke-RestMethod -Uri "$DEP_API_URL/repository/tags?per_page=100" -Method Get) | Write-Host "Retrieving repo tags from $DEP_API_URL/repository/tags?per_page=100"
Sort-Object -Property commit.created_at -Descending | $DEP_TAGS=$($(Invoke-RestMethod -Uri "$DEP_API_URL/repository/tags?per_page=100" -Method Get) |
Where-Object { $_.commit.created_at -eq "$CI_COMMIT_REF_NAME"} Sort-Object -Property commit.created_at -Descending)
$DEP_TAGS_BEFORE_DATE=$() Write-Host "DEP_TAGS = $DEP_TAGS"
# TAGS_BEFORE_DATE=$(jq --slurp --arg before_date "$PROJECT_CURR_TAG_DATE" '
# .[] Write-Host "Looking for latest release in $DEP_NAME before $CI_COMMIT_TAG was released on project $CI_PROJECT_NAME."
# | map(select(.commit.created_at != null and (.commit.created_at <= $before_date))) Write-Host "Retrieving repo tags from $DEP_API_URL/repository/tags?per_page=100"
# ' <<<"$DEP_TAGS") $DEP_TAGS_BEFORE_DATE=$($DEP_TAGS |
Where-Object { $_.commit.created_at -le "$REPO_CURR_TAG_DATE"})
# SELECTED_TAG="" Write-Host "Found $($DEP_TAGS_BEFORE_DATE.Count) tags pre-dating release $CI_COMMIT_TAG."
# if [[ $(jq length <<<"$TAGS_BEFORE_DATE") != 0 ]]; then $DEP_TAGS_BEFORE_DATE | Select-Object name | Out-String
# BRANCH_TO_PULL=$(jq -r '.[0].name' <<<"$TAGS_BEFORE_DATE")
# echo "Found release : $BRANCH_TO_PULL. Using it as \$BRANCH_TO_PULL."
# else
# echo "Found no release predating $CI_PROJECT_NAME $CI_COMMIT_TAG's date : $CI_COMMIT_TAG."
# echo "Retrieving latest repo tag."
# BRANCH_TO_PULL=$(jq -r '.[0].name' <<<"$DEP_TAGS")
# echo "\$BRANCH_TO_PULL = $BRANCH_TO_PULL"
# fi
if ( $($DEP_TAGS_BEFORE_DATE.Count) -ne 0) {
$BRANCH_TO_PULL=$DEP_TAGS_BEFORE_DATE[0].name
Write-Host "Found release : $BRANCH_TO_PULL. Using it as BRANCH_TO_PULL."
}
else {
Write-Host "Found no release predating $CI_PROJECT_NAME $CI_COMMIT_TAG's date : $CI_COMMIT_TAG."
Write-Host "Retrieving latest repo tag."
BRANCH_TO_PULL=$DEP_TAGS[0].name
Write-Host "\$BRANCH_TO_PULL = $BRANCH_TO_PULL"
}
########################################### ###########################################
# CASE CASUAL COMMIT or Draft MR PIPELINE # CASE CASUAL COMMIT or Draft MR PIPELINE
} else { } else {
...@@ -391,11 +392,10 @@ ...@@ -391,11 +392,10 @@
####################################################### #######################################################
# Retrieve JOB ID # Retrieve JOB ID
## Prepare pipelines to parse to retrieve the jobs of each pipelines ## Prepare pipelines to parse to retrieve the jobs of each pipelines
Write-Host "*************************************************************************" Write-Host "*************************************************************************"
Write-Host "*************************************************************************" Write-Host "*************************************************************************"
Write-Host "**" Write-Host "**"
Write-Host "** RETRIEVING LATEST SUCCESSFUL PIPELINES IN GIVEN BRANCH" Write-Host "** RETRIEVING LATEST SUCCESSFUL PIPELINES IN REF"
Write-Host "** $BRANCH_TO_PULL" Write-Host "** $BRANCH_TO_PULL"
Write-Host "**" Write-Host "**"
Write-Host "*************************************************************************" Write-Host "*************************************************************************"
......
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