|
| 1 | +# Stages |
| 2 | +# Stage-1: |
| 3 | + # Task-1: Build Docker Image and push to Docker Registry |
| 4 | + # Task-2: Copy kube-manifest files to Build Artifact Directory |
| 5 | + # Task-3: Publish build articats to Azure Pipelines |
| 6 | + # Task-4: Verify contents in System Source Directory |
| 7 | + # Task-5: Verify contents in Build Artifact Directory |
| 8 | +# Stage-2: |
| 9 | + # Task-1: Download Build Artifacts |
| 10 | + # Task-2: Deploy to Kubernetes |
| 11 | + |
| 12 | +trigger: |
| 13 | +- master |
| 14 | + |
| 15 | +variables: |
| 16 | + tag: '$(Build.BuildId)' |
| 17 | + |
| 18 | +stages: |
| 19 | +# Build Stage |
| 20 | +- stage: Build |
| 21 | + displayName: Build stage |
| 22 | + jobs: |
| 23 | + - job: Build |
| 24 | + displayName: Build job |
| 25 | + pool: |
| 26 | + vmImage: 'ubuntu-latest' |
| 27 | + steps: |
| 28 | + # List files from System Default Working Directory |
| 29 | + - bash: echo Initial Source Directory Files; ls -R $(System.DefaultWorkingDirectory); |
| 30 | + - bash: echo Image Tag $(Build.BuildId) |
| 31 | + # Task: Docker (Build and Push Images to Docker Registry) |
| 32 | + - task: Docker@2 |
| 33 | + inputs: |
| 34 | + containerRegistry: 'DockerHubStackSimplify' |
| 35 | + repository: 'stacksimplify/aks-github-dockerhub-nginxapp' |
| 36 | + command: 'buildAndPush' |
| 37 | + Dockerfile: '**/Dockerfile' |
| 38 | + tags: '$(tag)' |
| 39 | + - bash: echo Before copying to Build Artifact Directory; ls -R $(Build.ArtifactStagingDirectory) |
| 40 | + # Task: Copy files (Copy files from a source folder to target folder) |
| 41 | + - task: CopyFiles@2 |
| 42 | + inputs: |
| 43 | + SourceFolder: '$(System.DefaultWorkingDirectory)/kube-manifests' |
| 44 | + Contents: '**' |
| 45 | + TargetFolder: '$(Build.ArtifactStagingDirectory)' |
| 46 | + OverWrite: true |
| 47 | + # List files from Build Artifact Staging Directory - After Copy |
| 48 | + - bash: echo After copying to Build Artifact Directory; ls -R $(Build.ArtifactStagingDirectory) |
| 49 | + # Task: Publish build artifacts (Publish build to Azure Pipelines) |
| 50 | + - task: PublishBuildArtifacts@1 |
| 51 | + inputs: |
| 52 | + PathtoPublish: '$(Build.ArtifactStagingDirectory)' |
| 53 | + ArtifactName: 'kube-manifests' |
| 54 | + publishLocation: 'Container' |
| 55 | + - bash: echo After Published Build Artifacts to Pipeline; ls -R $(Build.ArtifactStagingDirectory) |
| 56 | + |
| 57 | +# Deploy Stage |
| 58 | +- stage: Deploy |
| 59 | + displayName: Deploy image |
| 60 | + jobs: |
| 61 | + - job: Deploy |
| 62 | + displayName: Deploy |
| 63 | + pool: |
| 64 | + vmImage: 'ubuntu-latest' |
| 65 | + steps: |
| 66 | + - bash: echo Before Download build Artifacts Step; ls -R $(Build.ArtifactStagingDirectory) |
| 67 | + # Task: Download build artifacts (Download files that were saved as artifacts of a completed build) |
| 68 | + - task: DownloadBuildArtifacts@0 |
| 69 | + inputs: |
| 70 | + buildType: 'current' |
| 71 | + downloadType: 'single' |
| 72 | + artifactName: 'kube-manifests' |
| 73 | + itemPattern: '**/*.yml' |
| 74 | + downloadPath: '$(System.ArtifactsDirectory)' |
| 75 | + - bash: echo After Download build Artifacts Step; ls -R $(Build.ArtifactStagingDirectory) |
| 76 | + # Task: Deploy to Kubernetes (User Kubernetes manifest files to deploy to AKS cluster) |
| 77 | + - task: KubernetesManifest@0 |
| 78 | + inputs: |
| 79 | + action: 'deploy' |
| 80 | + kubernetesServiceConnection: 'k8s-aksdemo1-svc-connection' |
| 81 | + namespace: 'default' |
| 82 | + manifests: '$(System.ArtifactsDirectory)/kube-manifests/*.yml' |
| 83 | + containers: 'stacksimplify/aks-github-dockerhub-nginxapp:$(tag)' |
| 84 | + |
0 commit comments