-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathazure-pipelines.yml
100 lines (82 loc) · 5.38 KB
/
azure-pipelines.yml
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#
# Build YAML file for Azure Data Factory Builds using the azure-data-factory-utilities Node package
# See: https://learn.microsoft.com/en-us/azure/data-factory/continuous-integration-delivery-improvements
# Requires a package.json file located in the target repository
#
# This version of the build also includes additional steps to commit the ARM templates generated
# to either deployments/main-adf-templates or deployments/release-adf-templates branches
# similar to the adf_publish behaviour with the manual publish (but based on build branch)
#
# main: configured as collaboration branch (Git Config in ADF Development instance)
# release: used for deployments to pre-production/production ADF instances
#
# Workflow:
# 1) Developer creates feature branch in ADF and makes changes on this branch
# 2) Developer raises Pull Request to merge to main
# 3) Merge to main branch triggers this build pipeline (on main), which generates Build Artifact, and adds ARM teplates to deployments/main-adf-templates branch
# 4) Release Pipeline is triggered from this build pipeline (based on new artifact) - Artifact filter based on "main" branch results in deployment to Development instance of ADF
# 5) Release Manager raised Pull Request (or Cherry Picks PRs) to merge to release
# 6) Merge to release branch triggers this build pipeline (on release), which generates Build Artifact, and adds ARM teplates to deployments/release-adf-templates branch
# 7) Release Pipeline is triggered from this build pipeline (based on new artifact) - Artifact filter based on "release" branch results in deployment to Pre-production instance of ADF
# 8) Approval then required on Release Pipeline to deploy to Production
#
trigger:
- none # use override YAML trigger to setup CI trigger on main/release
pool:
vmImage: 'ubuntu-latest'
variables:
- group: ADFDevOpsDemoPipelineVariables
steps:
- checkout: self
persistCredentials: true
# Installs Node and the npm packages saved in your package.json file in the build
- task: NodeTool@0
inputs:
versionSpec: '14.x'
displayName: 'Install Node.js'
- task: Npm@1
inputs:
command: 'install'
workingDir: '$(Build.Repository.LocalPath)/$(BuildFolder)' #replace with the package.json folder
verbose: true
displayName: 'Install npm package'
# Validates all of the Data Factory resources in the repository. You'll get the same validation errors as when "Validate All" is selected.
# Enter the appropriate subscription and name for the source factory.
- task: Npm@1
inputs:
command: 'custom'
workingDir: '$(Build.Repository.LocalPath)/$(BuildFolder)' #replace with the package.json folder
customCommand: 'run build validate $(Build.Repository.LocalPath)/$(ADFRootFolder) /subscriptions/$(SubscriptionID)/resourceGroups/$(ResourceGroup)/providers/Microsoft.DataFactory/factories/$(DataFactoryName)'
displayName: 'Validate'
# Validate and then generate the ARM template into the destination folder, which is the same as selecting "Publish" from the UX.
# The ARM template generated isn't published to the live version of the factory. Deployment should be done by using a CI/CD pipeline.
- task: Npm@1
inputs:
command: 'custom'
workingDir: '$(Build.Repository.LocalPath)/$(BuildFolder)' #replace with the package.json folder
customCommand: 'run build export $(Build.Repository.LocalPath)/$(ADFRootFolder) /subscriptions/$(SubscriptionID)/resourceGroups/$(ResourceGroup)/providers/Microsoft.DataFactory/factories/$(DataFactoryName) "$(ArmTemplateFolder)"'
#For using preview that allows you to only stop/ start triggers that are modified, please comment out the above line and uncomment the below line. Make sure the package.json contains the build-preview command.
#customCommand: 'run build-preview export $(Build.Repository.LocalPath)/$(ADFRootFolder) /subscriptions/$(SubscriptionID)/resourceGroups/$(ResourceGroup)/providers/Microsoft.DataFactory/factories/$(DataFactoryName) "$(ArmTemplateFolder)"'
displayName: 'Validate and Generate ARM template'
# Publish the artifact to be used as a source for a release pipeline.
- task: PublishPipelineArtifact@1
inputs:
targetPath: '$(Build.Repository.LocalPath)/$(BuildFolder)/$(ArmTemplateFolder)' #replace with the package.json folder
artifact: 'ArmTemplates'
publishLocation: 'pipeline'
# Configure Agent's Git Config (on occasion I've had a resource lock occur on this step - usually just re-run the build will work)
- script: |
git config --local user.email buildagent@adfautopublish.com & git config --local user.name "ADFAutoPublishAgent"
workingDirectory: $(System.DefaultWorkingDirectory)
continueOnError: true
# Checkout relevant deployment branch, and commit ARM templates folder to this branch (bit like adf_publish branch, but one for main, one for release)
- script: |
git checkout --orphan deployments/$(Build.SourceBranchName)-adf-templates
git rm -rf --cached .
cp -r $(BuildFolder)/$(ArmTemplateFolder)/ $(ArmTemplateFolder)/
git add $(ArmTemplateFolder)
git commit -m "deployment $(Build.BuildNumber)"
git pull origin deployments/$(Build.SourceBranchName)-adf-templates --allow-unrelated-histories --no-edit --rebase --strategy-option theirs
git push --set-upstream origin deployments/$(Build.SourceBranchName)-adf-templates
displayName: Commit ADF ARM Templates to deployments/$(Build.SourceBranchName)-adf-templates
workingDirectory: $(System.DefaultWorkingDirectory)