diff --git a/.gitlab/ci/shared_script.gitlab-ci.yml b/.gitlab/ci/shared_script.gitlab-ci.yml index 27e1187d6ece9987eba40cd08fb5f2f40b888533..1fd1699e06db6717a1d7011d19e8af2a12b549e8 100644 --- a/.gitlab/ci/shared_script.gitlab-ci.yml +++ b/.gitlab/ci/shared_script.gitlab-ci.yml @@ -31,3 +31,68 @@ - curl -f --location --output build_artifacts.zip "https://gitlab.eclipse.org/api/v4/projects/$DEPENDENCY_ID/jobs/artifacts/$BRANCH_TO_PULL/download?job=$DEPENDENCY_JOB" - unzip -o build_artifacts.zip -d . - rm -rf build_cpp + + +.download_dependency_windows: + # 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: + # Download dependencies + - $BRANCH_TO_PULL="dev" # default branch + - $STATUS_CODE_TARGET + # Check CI_MERGE_REQUEST_TARGET_BRANCH_NAME is available on dependency + - > + try { + $response = Invoke-RestMethod -Uri "https://gitlab.eclipse.org/eclipse/aidge/$DEPENDENCY_NAME/-/tree/$CI_MERGE_REQUEST_TARGET_BRANCH_NAME" -Method Get + $STATUS_CODE_TARGET=$response.StatusCode + } catch { + # Handle specific status codes + if ($_.Exception.Response -ne $null) { + $STATUS_CODE_TARGET = [int]$($_.Exception.Response.StatusCode) + } else { + Write-Host "Error: $($_.Exception.Message)" + } + } + - $STATUS_CODE_NAME + # Check CI_MERGE_REQUEST_TARGET_BRANCH_NAME is available on dependency + - > + try { + $response = Invoke-RestMethod -Uri "https://gitlab.eclipse.org/eclipse/aidge/$DEPENDENCY_NAME/-/tree/$CI_COMMIT_REF_NAME" -Method Get + $STATUS_CODE_NAME=$response.StatusCode + } catch { + # Handle specific status codes + if ($_.Exception.Response -ne $null) { + $STATUS_CODE_NAME = [int]$($_.Exception.Response.StatusCode) + } else { + Write-Host "Error: $($_.Exception.Message)" + } + } + - $DependencyId=(Invoke-RestMethod -Uri "https://gitlab.eclipse.org/api/v4/groups/$CI_PROJECT_NAMESPACE_ID/projects?search=$DEPENDENCY_NAME" -Method Get)[0].id + - > + if ($CI_MERGE_REQUEST_ID) { + Write-Host "Merge request pipeline detected" + if ($STATUS_CODE_TARGET -eq 404) { + Write-Host "Pull from default MR" + } + else { + # Pulling from target branch + Write-Host "Pull from $($CI_MERGE_REQUEST_TARGET_BRANCH_NAME)" + $BRANCH_TO_PULL = $CI_MERGE_REQUEST_TARGET_BRANCH_NAME + } + } + elseif ($STATUS_CODE_NAME -eq 404) { + Write-Host "Pull from default" + } + else { + # Pulling from branch with the same name + Write-Host "Pull from branch name" + $BRANCH_TO_PULL = $CI_COMMIT_REF_NAME + } + + - Write-Host "curling from https://gitlab.eclipse.org/api/v4/projects/5139/jobs/artifacts/$BRANCH_TO_PULL/download?job=$DEPENDENCY_JOB" + - 'curl "https://gitlab.eclipse.org/api/v4/projects/$DependencyId/jobs/artifacts/$BRANCH_TO_PULL/download?job=$DEPENDENCY_JOB" -o build_artifacts.zip' + + - Expand-Archive -Path build_artifacts.zip -DestinationPath . -Force + - Remove-Item .\build_cpp\ -Recurse -ErrorAction Ignore