-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathazure-pipelines.yml
More file actions
64 lines (50 loc) · 3.4 KB
/
Copy pathazure-pipelines.yml
File metadata and controls
64 lines (50 loc) · 3.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# Starter pipeline
# Start with a minimal pipeline that you can customize to build and deploy your code.
# Add steps that build, run tests, deploy, and more:
# https://aka.ms/yaml
trigger:
- master
pool:
vmImage: ubuntu-latest
variables:
- group: gp-api-key
- name: containerID
value: <container_id>
- name: serviceID
value: <service_id>
- name: applicationID
value: <application_id>
- name: projectID
value: <project_id>
- name: releaseID
value: <release_id>
- name: distributionID
value: <distribution_id>
- name: endPoint
value: <gopaddle_endpoint>
steps:
- script: |
# Trigger the build as soon as the code is committed
curl -H 'Authorization: Bearer $(GP_API_TOKEN)' -X POST -d '{"serviceID":"$(containerID)","releaseID":"$(releaseID)","distributionID":"$(distributionID)"}' https://$(endPoint)/gateway/v1/$(projectID)/build > buildInfo.json
cat buildInfo.json
# Get build ID and commit message from the build response
buildID="$(cat buildInfo.json | jq -r '.buildID')"
buildVersion="$(cat buildInfo.json | jq -r '.buildVersion')"
buildInProgress=true
commitMessage=`echo "$(Build.SourceVersionMessage)" | base64`
# Wait until build is complete
for (( ; ; ));do curl -H 'Authorization: Bearer $(GP_API_TOKEN)' https://$(endPoint)/gateway/v1/$(projectID)/build/$buildID > buildStatusInfo.json; buildStatus="$(cat buildStatusInfo.json | jq -r '.status')"; echo "$buildStatus"; if [[ $buildStatus == "Failed" ]]; then echo "build failed"; break; elif [[ $buildStatus == "Created" ]]; then echo "build Created successfully"; break; elif [[ $buildStatus == "Creating" ]]; then if [[ $buildInProgress == true ]]; then echo "build creating..."; buildInProgress=false; fi; continue; else echo "unknown status build dropped"; break; fi; done
displayName: 'Triggering Build'
- script: |
# Trigger Rolling Update
# Get build ID and commit message from the build response
buildID="$(cat buildInfo.json | jq -r '.buildID')"
buildVersion="$(cat buildInfo.json | jq -r '.buildVersion')"
buildInProgress=true
commitMessage=`echo "$(Build.SourceVersionMessage)" | base64`
buildStatus="$(cat buildStatusInfo.json | jq -r '.status')"
echo "Build ID is $buildID"
if [[ $buildStatus == "Created" ]]; then curl -H 'Authorization: Bearer $(GP_API_TOKEN)' -X PUT -d '{"serviceGroups":[{"services":[{"id":"$(containerID)","serviceVersion":"draft","releaseConfig":{"buildID":"'"$buildID"'","version":"'"$buildVersion"'"}}],"id":"$(serviceID)","name":"$(serviceName)","version":"draft","description":"'"$commitMessage"'"}],"deploymentTemplateVersion":"draft","updateType":"buildUpdate"}' https://$(endPoint)/gateway/v1/$(projectID)/application/$(applicationID) > rollingupdateinfo.json; rollingUpdateMessage="$(cat rollingupdateinfo.json | jq -r '.message')"; echo "$rollingUpdateMessage"; fi;
echo '{"serviceGroups":[{"services":[{"id":"$(containerID)","serviceVersion":"draft","releaseConfig":{"buildID":"'"$buildID"'","version":"'"$buildVersion"'"}}],"id":"$(serviceID)","name":"$(serviceName)","version":"draft","description":"'"$commitMessage"'"}],"deploymentTemplateVersion":"draft","updateType":"buildUpdate"}'
echo "Rolling Update Endpoint is https://$(endPoint)/gateway/v1/$(projectID)/application/$(applicationID)"
displayName: 'Creating Rolling Update'