diff --git a/job-templates.yml b/job-templates.yml index 5376730..413b2ec 100644 --- a/job-templates.yml +++ b/job-templates.yml @@ -55,3 +55,42 @@ render-job-templates-yml: - templates/** - job-templates.yml - job-templates.tpl.yml +render-pipelines-to-branch: + stage: render + image: "${CI_REGISTRY}/containerized-applications/ci-images/ci-scripts:1.0.2" + script: + # Begin of install-curl.sh + - | + #Install curl + apt update && apt install curl -y + # End of install-curl.sh + + # Begin of install-git.sh + - | + #Install git + apt update && apt install git -y + # End of install-git.sh + + # Begin of install-yq.sh + - "#Install YQ\n#\nexport YQ_VERSION=4.27.2\nexport YQ_ARCH=linux_amd64 \ncurl -fsSL \"https://github.com/mikefarah/yq/releases/download/v${YQ_VERSION}/yq_${YQ_ARCH}\" -o yq \nchmod +x yq\n" + # End of install-yq.sh + + # Begin of render-pipelines-branch.sh + - "#Replace main branch with current branch\nfor file in pipelines/*.yml\n do \n sed -i \"s;ref: 'main';ref: '$CI_COMMIT_BRANCH';g\" ./$file\ndone\nfor file in compliance/*.yml\n do \n sed -i \"s;ref: 'main';ref: '$CI_COMMIT_BRANCH';g\" ./$file\ndone\n" + # End of render-pipelines-branch.sh + + # Begin of commit-and-push-changes.sh + - | + # commit and push changes in job-templates.yml (if any) + git config user.name "DeveloperDurpBot" + git config user.email "DeveloperDurp@durp.info" + git add -A + git commit --untracked-files=no -m "ci: render" -m "Rendered by $CI_PIPELINE_URL" || exit 0 + echo "Pushing to branch $CI_COMMIT_BRANCH" + # just using -o ci.skip would create a "skipped" pipeline in the list of pipelines, preventing a merge! + # passing down CI_SCRIPTS_SKIP_PIPELINE and using this in workflow:rules is better, as it does not create a pipeline at all! + git push -o ci.variable="CI_SCRIPTS_SKIP_PIPELINE=true" "https://oauth2:${GITLAB_TOKEN}@${CI_SERVER_HOST}/${CI_PROJECT_PATH}.git" "HEAD:$CI_COMMIT_BRANCH" + curl --silent --fail --request POST --form token="$CI_JOB_TOKEN" --form ref="$CI_COMMIT_BRANCH" "$CI_API_V4_URL/projects/$CI_PROJECT_ID/trigger/pipeline" >/dev/null + # End of commit-and-push-changes.sh + rules: + - if: $CI_COMMIT_BRANCH =~ /^release*/