Skip to content

Commit c8406c1

Browse files
authored
Merge pull request #202875 from stevevi/steveviAzureGov10
Overhaul Deploy with Azure Pipelines article
2 parents 3f157c2 + 18293d8 commit c8406c1

File tree

2 files changed

+133
-50
lines changed

2 files changed

+133
-50
lines changed

articles/azure-government/connect-with-azure-pipelines.md

Lines changed: 133 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -4,94 +4,177 @@ description: Configure continuous deployment to your applications hosted in Azur
44
ms.service: azure-government
55
ms.topic: article
66
ms.custom: devx-track-azurepowershell
7-
ms.date: 03/02/2022
7+
recommendations: false
8+
ms.date: 06/27/2022
89
---
910

1011
# Deploy an app in Azure Government with Azure Pipelines
1112

12-
This article helps you use Azure Pipelines to set up continuous integration (CI) and continuous deployment (CD) of your web app running in Azure Government. CI/CD automates the build of your code from a repo along with the deployment (release) of the built code artifacts to a service or set of services in Azure Government. In this tutorial, you'll build a web app and deploy it to an Azure Governments app service. This build and release process is triggered by a change to a code file in the repo.
13+
This how-to guide helps you use Azure Pipelines to set up continuous integration (CI) and continuous delivery (CD) of your web app running in Azure Government. CI/CD automates the build of your code from a repository along with the deployment (release) of the built code artifacts to a service or set of services in Azure Government. In this how-to guide, you'll build a web app and deploy it to an Azure Governments App Service. The build and release process is triggered by a change to a code file in the repository.
1314

14-
[Azure Pipelines](/azure/devops/pipelines/get-started/what-is-azure-pipelines) is used by teams to configure continuous deployment for applications hosted in Azure subscriptions. We can use this service for applications running in Azure Government by defining [service connections](/azure/devops/pipelines/library/service-endpoints) for Azure Government.
15+
> [!NOTE]
16+
> [Azure DevOps](/azure/devops/) isn't available on Azure Government. While this how-to guide shows how to configure the CI/CD capabilities of Azure Pipelines to deploy an app to a service inside Azure Government, be aware that Azure Pipelines runs its pipelines outside of Azure Government. Research your organization's security and service policies before using it as part of your deployment tools. For guidance on how to use Azure DevOps Server to create a DevOps experience inside a private network on Azure Government, see [Azure DevOps Server on Azure Government](https://devblogs.microsoft.com/azuregov/azure-devops-server-in-azure-government/).
17+
18+
[Azure Pipelines](/azure/devops/pipelines/get-started/what-is-azure-pipelines) is used by development teams to configure continuous deployment for applications hosted in Azure subscriptions. We can use this service for applications running in Azure Government by defining [service connections](/azure/devops/pipelines/library/service-endpoints) for Azure Government.
1519

1620
[!INCLUDE [updated-for-az](../../includes/updated-for-az.md)]
1721

1822
## Prerequisites
1923

20-
Before starting this tutorial, you must complete the following prerequisites:
24+
Before starting this how-to guide, you must complete the following prerequisites:
2125

22-
+ [Create an organization in Azure DevOps](/azure/devops/organizations/accounts/create-organization)
23-
+ [Create and add a project to the Azure DevOps organization](/azure/devops/organizations/projects/create-project?;bc=%2fazure%2fdevops%2fuser-guide%2fbreadcrumb%2ftoc.json&tabs=new-nav&toc=%2fazure%2fdevops%2fuser-guide%2ftoc.json)
24-
+ Install and set up [Azure PowerShell](/powershell/azure/install-az-ps)
26+
- [Create an organization in Azure DevOps](/azure/devops/organizations/accounts/create-organization)
27+
- [Create and add a project to the Azure DevOps organization](/azure/devops/organizations/projects/create-project)
28+
- Install and set up [Azure PowerShell](/powershell/azure/install-az-ps)
2529

2630
If you don't have an active Azure Government subscription, create a [free account](https://azure.microsoft.com/global-infrastructure/government/request/) before you begin.
2731

28-
## Create Azure Government app service
29-
30-
[Create an App service in your Azure Government subscription](documentation-government-howto-deploy-webandmobile.md).
31-
The following steps will set up a CD process to deploy to this Web App.
32-
33-
## Set up Build and Source control integration
34-
35-
Follow through one of the quickstarts below to set up a Build for your specific type of app:
36-
37-
- [ASP.NET 4 app](/azure/devops/pipelines/apps/aspnet/build-aspnet-4)
38-
- [ASP.NET Core app](/azure/devops/pipelines/ecosystems/dotnet-core)
39-
- [Node.js app with Gulp](/azure/devops/pipelines/ecosystems/javascript)
40-
41-
## Generate a service principal
42-
43-
1. Download or copy and paste the [service principal creation](https://github.com/yujhongmicrosoft/spncreationn/blob/master/spncreation.ps1) PowerShell script into an IDE or editor.
44-
45-
> [!NOTE]
46-
> This script will be updated to use the Azure Az PowerShell module instead of the deprecated AzureRM PowerShell module.
47-
48-
2. Open up the file and navigate to the `param` parameter. Replace the `$environmentName` variable with
49-
AzureUSGovernment." This action sets the service principal to be created in Azure Government.
50-
51-
3. Open your PowerShell window and run the following command. This command sets a policy that enables running local files.
32+
## Create Azure Government App Service app
33+
34+
Follow [Tutorial: Deploy an Azure App Service app](./documentation-government-howto-deploy-webandmobile.md) to learn how to deploy an Azure App Service app to Azure Government. The following steps will set up a CD process to deploy to your web app.
35+
36+
## Set up build and source control integration
37+
38+
Review one of the following quickstarts to set up a build for your specific type of app:
39+
40+
- [ASP.NET 4](/azure/devops/pipelines/apps/aspnet/build-aspnet-4)
41+
- [.NET Core](/azure/devops/pipelines/ecosystems/dotnet-core)
42+
- [Node.js](/azure/devops/pipelines/ecosystems/javascript)
43+
44+
## Generate a service principal
45+
46+
1. Copy and paste the following service principal creation PowerShell script into an IDE or editor, and then save the script. This code is compatible only with Azure Az PowerShell v7.0.0 or higher.
47+
48+
```powershell
49+
param
50+
(
51+
[Parameter(Mandatory=$true, HelpMessage="Enter Azure subscription name - you need to be subscription admin to execute the script")]
52+
[string] $subscriptionName,
53+
54+
[Parameter(Mandatory=$false, HelpMessage="Provide SPN role assignment")]
55+
[string] $spnRole = "owner",
56+
57+
[Parameter(Mandatory=$false, HelpMessage="Provide Azure environment name for your subscription")]
58+
[string] $environmentName = "AzureUSGovernment"
59+
)
60+
61+
# Initialize
62+
$ErrorActionPreference = "Stop"
63+
$VerbosePreference = "SilentlyContinue"
64+
$userName = ($env:USERNAME).Replace(' ', '')
65+
$newguid = [guid]::NewGuid()
66+
$displayName = [String]::Format("AzDevOps.{0}.{1}", $userName, $newguid)
67+
$homePage = "http://" + $displayName
68+
$identifierUri = $homePage
69+
70+
# Check for Azure Az PowerShell module
71+
$isAzureModulePresent = Get-Module -Name Az -ListAvailable
72+
if ([String]::IsNullOrEmpty($isAzureModulePresent) -eq $true)
73+
{
74+
Write-Output "Script requires Azure PowerShell modules to be present. Obtain Azure PowerShell from https://docs.microsoft.com//powershell/azure/install-az-ps" -Verbose
75+
return
76+
}
77+
78+
Import-Module -Name Az.Accounts
79+
Write-Output "Provide your credentials to access your Azure subscription $subscriptionName" -Verbose
80+
Connect-AzAccount -Subscription $subscriptionName -Environment $environmentName
81+
$azureSubscription = Get-AzSubscription -SubscriptionName $subscriptionName
82+
$connectionName = $azureSubscription.Name
83+
$tenantId = $azureSubscription.TenantId
84+
$id = $azureSubscription.SubscriptionId
85+
86+
# Create new Azure AD application
87+
Write-Output "Creating new application in Azure AD (App URI - $identifierUri)" -Verbose
88+
$azureAdApplication = New-AzADApplication -DisplayName $displayName -HomePage $homePage -Verbose
89+
$appId = $azureAdApplication.AppId
90+
$objectId = $azureAdApplication.Id
91+
Write-Output "Azure AD application creation completed successfully (Application Id: $appId) and (Object Id: $objectId)" -Verbose
92+
93+
# Add secret to Azure AD application
94+
Write-Output "Creating new secret for Azure AD application"
95+
$secret = New-AzADAppCredential -ObjectId $objectId -EndDate (Get-Date).AddYears(2)
96+
Write-Output "Secret created successfully" -Verbose
97+
98+
# Create new SPN
99+
Write-Output "Creating new SPN" -Verbose
100+
$spn = New-AzADServicePrincipal -ApplicationId $appId
101+
$spnName = $spn.DisplayName
102+
Write-Output "SPN creation completed successfully (SPN Name: $spnName)" -Verbose
103+
104+
# Assign role to SPN
105+
Write-Output "Waiting for SPN creation to reflect in directory before role assignment"
106+
Start-Sleep 20
107+
Write-Output "Assigning role ($spnRole) to SPN app ($appId)" -Verbose
108+
New-AzRoleAssignment -RoleDefinitionName $spnRole -ApplicationId $spn.AppId
109+
Write-Output "SPN role assignment completed successfully" -Verbose
110+
111+
# Print values
112+
Write-Output "`nCopy and paste below values for service connection" -Verbose
113+
Write-Output "***************************************************************************"
114+
Write-Output "Connection Name: $connectionName(SPN)"
115+
Write-Output "Environment: $environmentName"
116+
Write-Output "Subscription Id: $id"
117+
Write-Output "Subscription Name: $connectionName"
118+
Write-Output "Service Principal Id: $appId"
119+
Write-Output "Tenant Id: $tenantId"
120+
Write-Output "***************************************************************************"
121+
```
122+
123+
2. Open your PowerShell window and run the following command, which sets a policy that enables running local files:
52124
53125
`Set-ExecutionPolicy -Scope Process -ExecutionPolicy Bypass`
54126
55-
When you're asked whether you want to change the execution policy, enter "A" (for "Yes to All").
127+
When asked whether you want to change the execution policy, enter "A" (for "Yes to All").
56128
57-
4. Navigate to the directory that has the edited script above.
129+
3. Navigate to the directory where you saved the service principal creation PowerShell script.
58130
59-
5. Edit the following command with the name of your script and run:
131+
4. Edit the following command with the name of your script and run:
60132
61133
`./<name of script file you saved>`
62134
63-
6. The "subscriptionName" parameter can be found by logging into your Azure Government subscription via `Connect-AzAccount -EnvironmentName AzureUSGovernment` and then running `Get-AzureSubscription`.
64-
65-
7. When prompted for the "password" parameter, enter your desired password.
135+
5. The "subscriptionName" parameter can be found by logging into your Azure Government subscription via `Connect-AzAccount -EnvironmentName AzureUSGovernment` and then running `Get-AzureSubscription`.
66136
67-
8. After providing your Azure Government subscription credentials, you should see the following message:
137+
6. After providing your Azure Government subscription credentials, you should see the following message:
68138
69-
> [!NOTE]
70-
> The Environment variable should be `AzureUSGovernment`.
139+
`The Environment variable should be AzureUSGovernment`
71140
72-
9. After the script has run, you should see your service connection values. Copy these values as we'll need them when setting up our endpoint.
141+
7. After the script has run, you should see your service connection values. Copy these values as we'll need them when setting up our endpoint.
73142
74-
![ps4](./media/documentation-government-vsts-img11.png)
143+
:::image type="content" source="./media/documentation-government-vsts-img11.png" alt-text="Service connection values displayed after running the PowerShell script." border="false":::
75144
76145
## Configure the Azure Pipelines service connection
77146
78-
Follow the instructions in [Service connections for builds and releases](/azure/devops/pipelines/library/service-endpoints) to set up the Azure Pipelines service connection.
147+
Follow [Manage service connections](/azure/devops/pipelines/library/service-endpoints) to set up the Azure Pipelines service connection.
148+
149+
Make one change specific to Azure Government:
79150
80-
Make one change specific to Azure Government: In step #3 of [Service connections for builds and releases](/azure/devops/pipelines/library/service-endpoints), click on "use the full version of the service connection catalog" and set **Environment** to **AzureUSGovernment**.
151+
- In step #3 of [Manage service connections: Create a service connection](/azure/devops/pipelines/library/service-endpoints#create-a-service-connection), click on *Use the full version of the service connection catalog* and set **Environment** to **AzureUSGovernment**.
81152
82153
## Define a release process
83154
84-
Follow [Deploy a web app to Azure App Services](/azure/devops/pipelines/apps/cd/deploy-webdeploy-webapps) instructions to set up your release pipeline and deploy to your application in Azure Government.
155+
Follow [Deploy an Azure Web App](/azure/devops/pipelines/targets/webapp) instructions to set up your release pipeline and deploy to your application in Azure Government.
85156
86157
## Q&A
87158
88159
**Do I need a build agent?** <br/>
89-
You need at least one [agent](/azure/devops/pipelines/agents/agents) to run your deployments. By default, the build and deployment processes are configured to use the [hosted agents](/azure/devops/pipelines/agents/agents#microsoft-hosted-agents). Configuring a private agent would limit data sharing outside of Azure Government.
160+
You need at least one [agent](/azure/devops/pipelines/agents/agents) to run your deployments. By default, the build and deployment processes are configured to use [hosted agents](/azure/devops/pipelines/agents/agents#microsoft-hosted-agents). Configuring a private agent would limit data sharing outside of Azure Government.
90161
91-
**I use Team Foundation Server on premises. Can I configure CD on my server to target Azure Government?** <br/>
92-
Currently, Team Foundation Server can't be used to deploy to an Azure Government Cloud.
162+
**Can I configure CD on Azure DevOps Server (formerly Team Foundation Server) to target Azure Government?** <br/>
163+
You can set up Azure DevOps Server in Azure Government. For guidance on how to use Azure DevOps Server to create a DevOps experience inside a private network on Azure Government, see [Azure DevOps Server on Azure Government](https://devblogs.microsoft.com/azuregov/azure-devops-server-in-azure-government/).
93164
94165
## Next steps
95166
96-
- Subscribe to the [Azure Government blog](https://devblogs.microsoft.com/azuregov/)
97-
- Get help on Stack Overflow by using the "[azure-gov](https://stackoverflow.com/questions/tagged/azure-gov)" tag
167+
For more information, see the following resources:
168+
169+
- [Sign up for Azure Government trial](https://azure.microsoft.com/global-infrastructure/government/request/?ReqType=Trial)
170+
- [Acquiring and accessing Azure Government](https://azure.microsoft.com/offers/azure-government/)
171+
- [Ask questions via the azure-gov tag on StackOverflow](https://stackoverflow.com/tags/azure-gov)
172+
- [Azure Government blog](https://devblogs.microsoft.com/azuregov/)
173+
- [What is Infrastructure as Code? – Azure DevOps](/devops/deliver/what-is-infrastructure-as-code)
174+
- [DevSecOps for infrastructure as code (IaC) – Azure Architecture Center](/azure/architecture/solution-ideas/articles/devsecops-infrastructure-as-code)
175+
- [Testing your application and Azure environment – Microsoft Azure Well-Architected Framework](/azure/architecture/framework/devops/release-engineering-testing)
176+
- [Azure Government overview](./documentation-government-welcome.md)
177+
- [Azure Government security](./documentation-government-plan-security.md)
178+
- [Compare Azure Government and global Azure](./compare-azure-government-global-azure.md)
179+
- [Azure Government compliance](./documentation-government-plan-compliance.md)
180+
- [Azure compliance](../compliance/index.yml)
236 KB
Loading

0 commit comments

Comments
 (0)