Skip to content

Commit 77ae1e8

Browse files
xumiajudyjoseph
authored andcommitted
[Ci] Support to trigger a pipeline to download and publish artifacts to storage (#10820)
Why I did it Support to trigger a pipeline to download and publish artifacts to storage and container registry. Support to specify the patterns which docker images to upload. How I did it Pass the pipeline information and the artifact information by pipeline parameters to the pipeline which will be triggered a new build. It is to decouple the artifacts generation and the publish logic, how and where the artifacts/docker images will be published, depends on the triggered pipeline. How to verify it
1 parent d628430 commit 77ae1e8

File tree

2 files changed

+69
-1
lines changed

2 files changed

+69
-1
lines changed

.azure-pipelines/azure-pipelines-image-template.yml

+5-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ jobs:
4848
ENABLE_DOCKER_BASE_PULL=y make PLATFORM=$(PLATFORM_AZP) PLATFORM_ARCH=$(PLATFORM_ARCH) $(BUILD_OPTIONS) configure
4949
displayName: 'Make configure'
5050
postSteps:
51-
- script: cp target -r $(Build.ArtifactStagingDirectory)/
51+
- script: mv target $(Build.ArtifactStagingDirectory)/
5252
displayName: Copy Artifacts
5353
condition: always()
5454
- publish: $(Build.ArtifactStagingDirectory)
@@ -58,6 +58,10 @@ jobs:
5858
condition: failed()
5959
artifact: 'sonic-buildimage.$(GROUP_NAME)$(GROUP_EXTNAME)$(System.JobAttempt)'
6060
displayName: "Archive failed sonic image"
61+
- template: trigger-publish-artifacts-build.yml
62+
parameters:
63+
artifactName: 'sonic-buildimage.$(GROUP_NAME)$(GROUP_EXTNAME)'
64+
publishPrefix: '$(Build.DefinitionName)/$(Build.SourceBranchName)/$(GROUP_NAME)'
6165
- ${{ parameters.postSteps }}
6266
- template: cleanup.yml
6367
jobGroups: ${{ parameters.jobGroups }}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
# The steps to trigger the pipeline to publish the artifacts
2+
3+
parameters:
4+
- name: artifactName
5+
type: string
6+
default: ""
7+
- name: publishPrefix
8+
type: string
9+
default: "$(Build.DefinitionName)/$(Build.SourceBranchName)"
10+
11+
steps:
12+
- script: |
13+
. functions.sh
14+
sonic_version=$(sonic_get_version)
15+
latest_tag=$(git describe --tags --abbrev=0)
16+
docker_tags="$sonic_version $(Build.SourceBranchName)"
17+
if [ "$(Build.SourceBranchName)" == "master" ]; then
18+
docker_tags="$docker_tags latest"
19+
fi
20+
echo "##vso[task.setvariable variable=sonic_version]$sonic_version"
21+
echo "##vso[task.setvariable variable=latest_tag]$latest_tag"
22+
echo "##vso[task.setvariable variable=docker_tags]$docker_tags"
23+
condition: ne(variables['Build.Reason'], 'PullRequest')
24+
displayName: 'Set trigger build variables'
25+
- task: TriggerBuild@4
26+
condition: ne(variables['Build.Reason'], 'PullRequest')
27+
inputs:
28+
definitionIsInCurrentTeamProject: false
29+
teamProject: internal
30+
tfsServer: $(System.CollectionUri)
31+
buildDefinition: 'publish-artifacts'
32+
queueBuildForUserThatTriggeredBuild: true
33+
ignoreSslCertificateErrors: false
34+
useSameSourceVersion: false
35+
useCustomSourceVersion: false
36+
useSameBranch: false
37+
waitForQueuedBuildsToFinish: false
38+
storeInEnvironmentVariable: true
39+
authenticationMethod: 'Personal Access Token'
40+
password: '$(system.accesstoken)'
41+
enableBuildInQueueCondition: false
42+
dependentOnSuccessfulBuildCondition: false
43+
dependentOnFailedBuildCondition: false
44+
checkbuildsoncurrentbranch: false
45+
failTaskIfConditionsAreNotFulfilled: false
46+
buildParameters: ''
47+
templateParameters: |
48+
pipelineContext: {"buildId":"$(Build.BuildId)",
49+
"pipelineId":"$(System.DefinitionId)",
50+
"project": "$(System.TeamProject)",
51+
"branchName":"$(Build.SourceBranchName)"},
52+
artifactContext: {"artifactName":"${{ parameters.artifactName }}",
53+
"artifactPatterns":"**/*.bin\n
54+
**/*.swi\n
55+
**/*.raw\n
56+
**/*.img.gz\n
57+
**/*-rpc.gz\n
58+
**/python-saithrift*.deb"},
59+
publishContext: {"publishPrefix":"${{ parameters.publishPrefix }}",
60+
"keepArtifactName":false,
61+
"dockerImagePatterns":"target/*-rpc.gz",
62+
"dockerTags":"$(docker_tags)",
63+
"version":"$(sonic_version)",
64+
"latestTag":"$(latest_tag)"}

0 commit comments

Comments
 (0)