Files
yml/jobs/gitlab.yml

81 lines
3.0 KiB
YAML

.gitlab-move-files:
image: registry.internal.durp.info/debian:latest
script:
# Begin of movefiles.sh
- |
#move files to output
mkdir $CI_PROJECT_DIR/output
for i in $(echo $PROJECT_NAME | tr ";" "\n");
do mkdir $CI_PROJECT_DIR/output/$i;
cp -r $CI_PROJECT_DIR/$i $CI_PROJECT_DIR/output/;
done
# End of movefiles.sh
artifacts:
expire_in: 1 hour
paths:
- $CI_PROJECT_DIR/output
.gitlab-deploy:
stage: deploy
image: mcr.microsoft.com/powershell:latest
script:
# Begin of update-chart.sh
- |
pwsh -c "Install-Module -Name powershell-yaml -Confirm:\$false -Force
\$template = (Invoke-RestMethod -Headers @{ 'PRIVATE-TOKEN'= \$ENV:GITLAB_TOKEN } -Uri \"https://gitlab.com/api/v4/projects/45028985/repository/files/durpapi%2FChart.yaml/raw?ref=main\") | ConvertFrom-Yaml
\$template.version = \$ENV:VERSION
\$body = @{
branch = \"main\"
commit_message = \"Update Chart\"
content = \"\$(\$template | convertto-yaml)\"
} | ConvertTo-Json
Invoke-RestMethod -Headers @{ 'PRIVATE-TOKEN'= \$ENV:GITLAB_TOKEN } -ContentType \"application/json\" -Method Put -body \$body -Uri \"https://gitlab.com/api/v4/projects/45028985/repository/files/durpapi%2FChart.yaml\""
# End of update-chart.sh
environment:
name: production
url: https://api.durp.info/goapi
rules:
- if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH || $CI_COMMIT_BRANCH =~ '/^release/'
when: manual
needs:
- job: version
artifacts: true
.generate-config:
stage: build
needs:
- job: version
artifacts: true
script:
# Begin of create-environment.sh
- |
#test deployment
echo "
$VERSION:
stage: deploy
image: mcr.microsoft.com/powershell:latest
script:
" >> generated-config.yml
echo '
- |
pwsh -c "Install-Module -Name powershell-yaml -Confirm:\$false -Force
\$template = (Invoke-RestMethod -Headers @{ \"PRIVATE-TOKEN\"= \$ENV:GITLAB_TOKEN } -Uri \"\$ENV:CI_API_V4_URL/projects/\$ENV:GITLAB_PROJECT_ID/repository/files/\$ENV:GITLAB_CHART_PATH/raw?ref=\$ENV:ENVIRONMENT\") | ConvertFrom-Yaml
\$template.version = \$ENV:VERSION
\$body = @{
branch = \"\$ENV:ENVIRONMENT\"
commit_message = \"Update Chart\"
content = \"\$(\$template | convertto-yaml)\"
} | ConvertTo-Json
Invoke-RestMethod -Headers @{ \"PRIVATE-TOKEN\"= \$ENV:GITLAB_TOKEN } -ContentType \"application/json\" -Method Put -body \$body -Uri \"\$ENV:CI_API_V4_URL/projects/\$ENV:GITLAB_PROJECT_ID/repository/files/\$ENV:GITLAB_CHART_PATH\""
needs:
- pipeline: $PARENT_PIPELINE_ID
job: version
' >> generated-config.yml
echo "
environment:
name: $ENVIRONMENT
" >> generated-config.yml
# End of create-environment.sh
artifacts:
expire_in: never
paths:
- generated-config.yml