|
| 1 | +name: '$(Date:yyyy)-$(Date:MM)-$(Date:dd)$(Rev:.r)' |
| 2 | + |
| 3 | +trigger: |
| 4 | + batch: true |
| 5 | + branches: |
| 6 | + include: |
| 7 | + - main |
| 8 | + - refs/tags/* |
| 9 | + |
| 10 | +pr: |
| 11 | + branches: |
| 12 | + include: |
| 13 | + - main |
| 14 | + drafts: false |
| 15 | + autoCancel: true |
| 16 | + paths: |
| 17 | + exclude: |
| 18 | + - .github/** |
| 19 | + - .devcontainer/** |
| 20 | + - .vscode/** |
| 21 | + - README.md |
| 22 | + - LICENSE |
| 23 | + |
| 24 | +stages: |
| 25 | +- stage: Build |
| 26 | + jobs: |
| 27 | + - job: Build |
| 28 | + |
| 29 | + pool: |
| 30 | + vmImage: 'ubuntu-latest' |
| 31 | + |
| 32 | + steps: |
| 33 | + - checkout: self |
| 34 | + fetchDepth: 0 # no shallow fetch, we need all the history for GitVersion to work |
| 35 | + |
| 36 | + - task: gitversion/setup@0 |
| 37 | + displayName: Setup GitVersion |
| 38 | + inputs: |
| 39 | + versionSpec: '5.x' |
| 40 | + |
| 41 | + - task: gitversion/execute@0 |
| 42 | + displayName: Determine Version |
| 43 | + name: GitVersion |
| 44 | + inputs: |
| 45 | + useConfigFile: true |
| 46 | + configFilePath: '$(Build.SourcesDirectory)/GitVersion.yml' |
| 47 | + |
| 48 | + - task: replacetokens@3 |
| 49 | + displayName: 'Replace tokens in main.parameters.json' |
| 50 | + inputs: |
| 51 | + rootDirectory: '$(Build.SourcesDirectory)' |
| 52 | + targetFiles: 'main.parameters.json' |
| 53 | + actionOnMissing: fail |
| 54 | + verbosity: detailed |
| 55 | + |
| 56 | + # Compile bicep file to JSON to make it independent |
| 57 | + - script: | |
| 58 | + bicep build main.bicep --outfile main.json |
| 59 | + displayName: 'Compile bicep file' |
| 60 | + workingDirectory: $(Build.SourcesDirectory) |
| 61 | +
|
| 62 | + - task: CopyFiles@2 |
| 63 | + displayName: 'Copy files to drop folder' |
| 64 | + inputs: |
| 65 | + SourceFolder: $(Build.SourcesDirectory) |
| 66 | + Contents: | |
| 67 | + main.bicep |
| 68 | + main.json |
| 69 | + main.parameters.json |
| 70 | + TargetFolder: $(Build.ArtifactStagingDirectory)/drop |
| 71 | + |
| 72 | + - task: PublishPipelineArtifact@1 |
| 73 | + displayName: "Publish drop artifact" |
| 74 | + inputs: |
| 75 | + targetPath: $(Build.ArtifactStagingDirectory)/drop |
| 76 | + artifactName: "drop" |
| 77 | + |
| 78 | + - task: AzureCLI@2 |
| 79 | + displayName: "Validate Resources" |
| 80 | + condition: | |
| 81 | + and |
| 82 | + ( |
| 83 | + succeeded(), |
| 84 | + startsWith(variables['Build.SourceBranch'], 'refs/pull/') |
| 85 | + ) |
| 86 | + inputs: |
| 87 | + azureSubscription: $(azureConnection) |
| 88 | + scriptType: bash |
| 89 | + scriptLocation: inlineScript |
| 90 | + inlineScript: > |
| 91 | + az deployment group validate |
| 92 | + --resource-group '$(resourceGroupName)' |
| 93 | + --template-file $(Build.SourcesDirectory)/main.json |
| 94 | + --parameters $(Build.SourcesDirectory)/main.parameters.json |
| 95 | +
|
| 96 | +- stage: Deploy |
| 97 | + displayName: Deploy |
| 98 | + dependsOn: Build |
| 99 | + # only deploy non pr branches |
| 100 | + condition: | |
| 101 | + and |
| 102 | + ( |
| 103 | + succeeded(), |
| 104 | + not(startsWith(variables['Build.SourceBranch'], 'refs/pull/')) |
| 105 | + ) |
| 106 | + jobs: |
| 107 | + - deployment: Deploy |
| 108 | + environment: Dependabot |
| 109 | + |
| 110 | + pool: |
| 111 | + vmImage: 'ubuntu-latest' |
| 112 | + |
| 113 | + strategy: |
| 114 | + runOnce: |
| 115 | + deploy: |
| 116 | + steps: |
| 117 | + |
| 118 | + - task: AzureCLI@2 |
| 119 | + displayName: "Deploy Resources" |
| 120 | + inputs: |
| 121 | + azureSubscription: $(azureConnection) |
| 122 | + scriptType: bash |
| 123 | + scriptLocation: inlineScript |
| 124 | + inlineScript: > |
| 125 | + az deployment group create |
| 126 | + --resource-group '$(resourceGroupName)' |
| 127 | + --template-file $(Pipeline.Workspace)/drop/main.json |
| 128 | + --parameters $(Pipeline.Workspace)/drop/main.parameters.json |
0 commit comments