Show deployed application versions in Environments tab - azure-devops

I have a deployment pipeline in azure-devops and it takes artifacts from other pipelines and deploy it to different environments. Yml looks like this:
...
resources:
repositories:
- repository: self
trigger:
branches:
include:
- develop
- release
- master
pipelines:
- pipeline: pipeline-1
source: different-repo-pipeline-1
- pipeline: pipeline-2
source: different-repo-pipeline-2
...
jobs:
- deployment: some-name
environment: develop
strategy:
runOnce:
deploy:
steps:
- download: pipeline-1
- download: pipeline-2
# Do real deployment
After deployment on target environment tab I saw:
There is no clue on it about deployed versions. I know this version inside deployment steps, or at least can use variables from pipelines (resources.pipeline.pipeline-1.runName). But I don't see any options to add this info to Environment deployment tab. Can it be done in some ways?

No, this is not possible. We don't have any way to control what is displayed on environment tab.

Related

How to specify dynamic value as environment name for virtual machine resource in yaml pipelines

We are planning to move our release pipelines to yaml and we are ready with it.
I have multiple environments like dev, test and prod where I'm trying to use same deployment job templates for all environments.
jobs:
- deployment: deploy
displayName: Deploy
environment:
name: dev # This should be replaced with environment specific variable
resourceType: VirtualMachine
tags: WEB01
In above code, my intension is to provide name as environment specific variable. Could someone pls help?
Thank you!
You can do this with parameters, but you need to use the expression syntax which is evaluated when the pipeline is compiled
parameters:
- name: environment
type: string
default: dev
values:
- dev
- test
- preprod
- prod
jobs:
- deployment: deploy
displayName: Deploy
environment:
name: ${{ parameters.environment }}
resourceType: VirtualMachine
tags: WEB01
You might like my answer in another post. it does stages per environment with approvals.
https://stackoverflow.com/a/74159554/4485260

Using an Azure DevOps YAML deployment pipeline, the zip file does not unzip into the Azure App Service

I am building out a new yaml-based build process, provisioning via terraform, using Azure GIT repos. The release pipeline uses a yaml file (below) and I know all of the rest of it works because the whole deployment works except the deploy just drops the .zip file in the site/wwwroot directory instead of unzipping it. As far as I can tell it is all about the last two lines in the deploy section at the very bottom of the file.
Also, the package and zip themselves are fine, as I was able to manually deploy the code via Azure CLI in VS Code and it works.
Do I need something else to get the release to unzip the zip contents into the wwwroot dir?
name: Deploy $(Date:yyyyMMdd)$(Rev:.r) # build numbering format
trigger: none
resources:
repositories:
- repository: templates
type: git
name: repo/branch
ref: refs/heads/main
pipelines:
- pipeline: build
project: ADOProject
source: buildpipelinename
trigger:
branches:
- dev
variables:
- name: tier_prefix
value: D
- name: env_identifier
value: dev
- name: workstream
value: liehadmin
- name: region_prefix
value: C
- name: rgp_identifier
value: OURRGP
- group: terraform (non-prod)
stages:
- stage: infrastructure # our terraform methods are called from here
condition: and(succeeded(), in(variables['Build.Reason'], 'IndividualCI', 'BatchedCI', 'Manual', 'Schedule', 'ResourceTrigger'))
displayName: UPDATE INFRASTRUCTURE
jobs:
- template: 'core/terraform.yaml#templates'
parameters:
tier_prefix: $(tier_prefix)
tf_key: $(workstream)-$(env_identifier)
module_name: 'web_1tier1region_S'
variable_file_path: "$(System.DefaultWorkingDirectory)/$(Build.Repository.Name)/pipelines/$(workstream)/$(workstream).$(env_identifier).tfvars.json"
- stage: deploy
dependsOn: [infrastructure]
displayName: DEPLOY APP
jobs:
# Track deployments on the environment.
- deployment: DeployWeb
displayName: deploy Web App
pool:
vmImage: 'windows-latest'
# Creates an environment if it doesn't exist.
environment: 'site-dev'
strategy:
# Default deployment strategy, more coming...
runOnce:
deploy:
steps:
- checkout: self
- bash: ls $BUILD_ARTIFACTSTAGINGDIRECTORY
- bash: ls $PIPELINE_WORKSPACE
- task: AzureRmWebAppDeployment#4
displayName: 'deploy $(tier_prefix)-$(region_prefix)-$(workstream)-UI-01'
inputs:
ConnectionType: 'AzureRM'
azureSubscription: 'subname'
# SlotName: 'slot'
appType: 'webApp'
WebAppName: '$(tier_prefix)-$(region_prefix)-$(workstream)-UI-01'
ResourceGroupName: '$(region_prefix)-Y-Z-$(rgp_identifier)-$(tier_prefix)-XXX-XX'
# DeployToSlotOrASEFlag: true
Package: '$(Pipeline.Workspace)/build/repo_name'
enableCustomDeployment: true
deploymentMethod: 'zipDeploy'
I might have found the fix:
UseWebDeploy: true
enableCustomDeployment: true
deploymentMethod: 'runFromPackage'
Now, if you read the Microsoft documentation, this is weird, since it lists enableCustomDeployment as an argument alias for UseWebDeploy, but for some reason using both worked; my code deployed to site/wwwroot.
I too struggled with this and found this:
Go to App Service -> Configuration
Add a new Application Setting: WEBSITE_RUN_FROM_PACKAGE = 1
Go to App Service -> Console. Run the command dir
You should find, that the contents of your zip file is now shown, and that the site works.
You can read more here: https://github.com/projectkudu/kudu/wiki/WEBSITE_RUN_FROM_PACKAGE-and-WEBSITE_CONTENTAZUREFILECONNECTIONSTRING-Best-Practices

How to pass in environment variables when deploying to AKS from Azure DevOps

I want to deploy a custom SQL Server image, which needs 4 environment variables passed in to AKS using the following pipeline definition:
jobs:
- deployment: Deploy
condition: and(succeeded(), not(startsWith(variables['Build.SourceBranch'], 'refs/pull/')))
displayName: Deploy
pool:
vmImage: $(vmImageName)
environment: 'xxxx.default'
strategy:
runOnce:
deploy:
steps:
- task: KubernetesManifest#0
displayName: Create imagePullSecret
inputs:
action: createSecret
namespace: $(k8sNamespace)
secretName: $(imagePullSecret)
dockerRegistryEndpoint: $(dockerRegistryServiceConnection)
- task: KubernetesManifest#0
displayName: Deploy to Kubernetes cluster
inputs:
action: deploy
namespace: $(k8sNamespace)
manifests: |
$(Pipeline.Workspace)/manifests/deployment.yml
$(Pipeline.Workspace)/manifests/service.yml
imagePullSecrets: |
$(imagePullSecret)
containers: |
$(containerRegistry)/$(imageRepository):$(tag)
The manifest files are created by Azure DevOps in this instance, so how would I go along, if I wanted to inject the SA_Password / inistial user configuration for this container?
https://learn.microsoft.com/en-us/azure/devops/pipelines/tasks/deploy/kubernetes-manifest?view=azure-devops#deploy-action
kubernetes-manifest deploy action doesn't have the option to add extra environment variables. Feel free to open a feature request at https://github.com/microsoft/azure-pipelines-tasks/issues
You can do two options, write a script with yq (https://github.com/mikefarah/yq) to update the manifest files before deployment
Or use the KubernetesManifest patch option (https://learn.microsoft.com/en-us/azure/devops/pipelines/tasks/deploy/kubernetes-manifest?view=azure-devops#patch-action), for example
steps:
- task: KubernetesManifest#0
displayName: Patch
inputs:
action: patch
kind: pod
name: demo-5fbc4d6cd9-pgxn4
mergeStrategy: strategic
patch: '{"spec":{"template":{"spec":{"containers":[{"env":[{"name":"SA_Password","value":"1234"}]}]}}}}'
kubernetesServiceConnection: someK8sSC
namespace: default
My contribution to Tummala comment is that if you have control over how the docker image is built, I suggest adding env variables from there instead. So if you have a docker build that is triggered when commiting on the develop branch, you can just pass that env to that docker image.
I have a dedicated post talking about CI/CD in Azure DevOps, in case you're interested in: Building CI/CD pipelines for Kubernetes with Azure DevOps and GitFlow.

How to add Pre Deployment and Post deployment approvals in multistage YAML pipeline?

I have a Multistage YAML pipeline containing two stages 1) Build and 2) Deploy. Deploy stage is mentioned below and I want to add pre deploy approvals in that stage before deploy task. How can I add pre deployment and Post deployment approvals in multistage YAML pipeline?
stages:
- stage: 'Build'
# RESTORE
# Some task implementation
# BUILD
# Some task implementation
# PUBLISH
# Some task implementation
# DEPLOY STAGE
- stage: 'Dev'
displayName: 'Deploy to the dev environment'
dependsOn: Build
jobs:
- deployment: Deploy
pool:
vmImage: 'ubuntu-16.04'
environment: dev
variables:
- group: Release
strategy:
# HOW TO ADD PRE DEPLOYMENT AND POST DEPLOYMENT APPROVALS?
runOnce:
deploy:
steps:
- download: current
artifact: drop
- task: AzureWebApp#1
displayName: 'Azure App Service Deploy: website'
inputs:
azureSubscription: 'Resource Manager - Tailspin - Space Game'
appName: '$(WebAppNameDev)'
package: '$(Pipeline.Workspace)/drop/$(buildConfiguration)/*.zip'
For this issue ,currently, manual approval and evaluate artifact are the only available checks, and they can be configured on environments, service connections and agent pools only.
To define an approval on an environment:
In your Azure DevOps project, go to the environment that needs to be protected. (Learn more about creating an environment.)
Navigate to Approvals and Checks for the environment.
Select Create, provide the approvers and an optional message, and select Create again to to complete addition of the manual approval check.
Then use the environment: 'xxx' parameter in your yaml file. For example:
- stage: deploy
jobs:
- deployment: DeployWeb
displayName: deploy Web App
pool:
vmImage: 'Ubuntu-16.04'
# creates an environment if it doesn't exist
environment: 'multiStage'
The GUI and the yaml are interdependent in this case, it's not straight yaml.
For details ,please refer to this official document.

azure devops yaml pipeline with template does not checkout referenced repository

I am using the new Azure DevOps Yaml multi stage pipeline functionality
I've got an Azure DevOps yaml pipeline file for which I want to use templates. I would like the pipeline to checkout self and another repository.
For some reason, self repo has been checked out when this runs, but the repo: pipelines is not being checked out and therefore the job fails (because some of the file dependencies it requires are not there.
Here is an excerpt from my template:
resources:
repositories:
- repository: self
- repository: pipelines
name: vstsproject/pipelines
type: git
source: pipelines
variables:
# Container registry service connection established during pipeline creation
imageRepository: 'vstsprojectweb'
dockerfilePath: '$(Build.SourcesDirectory)/src/Dockerfile.CI'
BuildConfiguration: 'Release'
tag: '$(Build.BuildId)'
stages:
- stage: 'PRD'
jobs:
- template: update-connection-string-db.yml#pipelines
parameters:
resourceGroup: 'application-DEV'
DBSearchString: '###dbservername###'
What is it that I am doing wrong?
I have referred to this microsoft documentation.
You don't need to reference the linked repo in the resources (i.e. self), and if it is the only repo, then it is checked out by default in jobs (not deployment jobs), but if you have additional repos, then you need to check them out manually (with -checkout: <name_of_repo>).
So just do (PS: Cleaned up a little, assumed that the repo is in the same project):
resources:
repositories:
- repository: pipelines
source: pipelines
variables:
# Container registry service connection established during pipeline creation
imageRepository: 'vstsprojectweb'
dockerfilePath: '$(Build.SourcesDirectory)/src/Dockerfile.CI'
BuildConfiguration: 'Release'
tag: '$(Build.BuildId)'
stages:
- stage: 'PRD'
jobs:
- checkout: self
- checkout: pipelines
- template: update-connection-string-db.yml#pipelines
parameters:
resourceGroup: 'application-DEV'
DBSearchString: '###dbservername###'
I ended up putting everything into the same repo and then checking out self in a job.
That worked for me.
jobs:
- job: dbconnectionstring
displayName: 'db connection string'
pool: Windows
steps:
- checkout: self
- template: templates/update-connection-string-db.yml