Skip to content

Add support for Azure DevOps in azd pipeline config - #693

Closed
hattan wants to merge 35 commits into
Azure:mainfrom
kaizentm:add-azdo-provider
Closed

Add support for Azure DevOps in azd pipeline config#693
hattan wants to merge 35 commits into
Azure:mainfrom
kaizentm:add-azdo-provider

Conversation

@hattan

@hattan hattan commented Sep 17, 2022

Copy link
Copy Markdown
Contributor

This PR fixes #101, #708, #699 and #702 and adds support for Azure DevOps an SCM and CI provider.

This new workflow enables the following:

  • Pipeline named providers for GitHub github and Azure DevOps azdo

  • The provider can be specified in two ways:

    • via azure.yaml by defining the following section:
      pipelines:
         - provider: azdo
      This providers a permanent mechanism for switcing to Azure DevOps as a pipeline provider.
    • Via the --provider flag
       azd pipeline config --provider azdo
      This method updates the provider for only this command invocation. Subsequent pipeline config commands will default to github, unless --provider is passed in.
  • Detection of provider based on .azdo or .github in the template augments the above behavior.

    • If only a .github folder exists, it is assumed the provider is github if azdo is set as a provider value, this will result in an error
    • If only a .azdo folder exists, it is assume the provider is azdo. If github is set as the provider value, this will result in an error.
    • If both .azdo and .github folder exists, the Azure Developer CLI will not make a determination and rely on the user to provide a pipeline provider.
  • AzDo provider supports using an existing project.

  • AzDo provider supports creating a new project.

  • AzDo provider supports using an existing repo.

  • AzDo provider supports creating a new repo in a project.

  • PAT authentication is used to push to the new repo, and the tool checks for credential helper and offers to set it to store to make subsequent pushes easier.

  • If a PAT is not provided, the tool will ask the user for a PAT and ask the user if they would like to store it.

  • If an organization name is not provided via an Environment Variable, the user will be prompted for an organization name and it will be stored in the environment file.

  • AzDo provider creates a build policy to ensure pushes to default branch are disabled and require a successful pipeline invocation.

  • Deployment Pipeline is created

  • Service Connection is created to allow the pipeline to deploy to azure.

  • Initial pipeline deployment is queued to follow the github behavior.

This was tested with a full deployment of todo-python-mongo using an Azure DevOps Pipeline.
image

image

image

@hattan hattan changed the title Add azdo provider Add support for Azure DevOps in azd pipeline config Sep 17, 2022
* Refactor to introduce new azdo package

* refactor azdo code to multiple files in azdo package

* Added azdo connection test and refactored provider

* Added azdo provider initial tests

* added more azdo provider tests

* Adding test to verify save env config in azdo provider

* Updating displayed urls to aka.ms
@hattan
hattan marked this pull request as ready for review September 19, 2022 07:49
Comment thread cli/azd/pkg/azdo/azdo.go Outdated
Comment thread cli/azd/pkg/azdo/pipeline.go Outdated
Comment thread cli/azd/pkg/commands/pipeline/pipeline_manager.go Outdated
Comment thread cli/azd/pkg/commands/pipeline/pipeline_manager.go Outdated
hattan and others added 3 commits September 20, 2022 18:26
* Adding service connection name to pipeline variables

* Checking for service connection exists and also removing do push condition

* Check for pipeline exists and update the name to include repo if exists.

* adding provider arg and setting variables only for terraform (#46)

* Set default pipeline provider to github

* Adjust project creation wait time.

* prompt for pat and org name if not in system env vars.

* Azure DevOps name standardization

* Update Azdo readme.

* refactor to fix failing test

Co-authored-by: Victor Vazquez <victor.vazquez@microsoft.com>
Comment thread cli/azd/cmd/pipeline.go
local.StringVar(&p.manager.PipelineServicePrincipalName, "principal-name", "", "The name of the service principal to use to grant access to Azure resources as part of the pipeline.")
local.StringVar(&p.manager.PipelineRemoteName, "remote-name", "origin", "The name of the git remote to configure the pipeline to run on.")
local.StringVar(&p.manager.PipelineRoleName, "principal-role", "Contributor", "The role to assign to the service principal.")
local.StringVar(&p.manager.PipelineProvider, "provider", "github", "The pipeline provider to use (GitHub and Azdo supported).")

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
local.StringVar(&p.manager.PipelineProvider, "provider", "github", "The pipeline provider to use (GitHub and Azdo supported).")
local.StringVar(&p.manager.PipelineProvider, "provider", "github", "The pipeline provider to use (github and azdo supported).")

Comment thread cli/azd/cmd/pipeline.go Outdated
Comment thread cli/azd/pkg/azdo/azdo.go
)

var (
AzDoHostName = "dev.azure.com" // hostname of the AzDo PaaS service.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this overridable for self-host situations.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, these variable are exported as part of the AzDo package and overridable. We can add helper method to make it easier, but they were built specifically with the idea that we could override to use a self host AzDo server.

After this PR I will set up a self hosted AzDo and test against that.

Comment thread cli/azd/pkg/azdo/azdo.go
AzurePipelineName = "Azure Dev Deploy" // name of the azure pipeline that will be created
AzurePipelineYamlPath = ".azdo/pipelines/azure-dev.yml" // path to the azure pipeline yaml
CloudEnvironment = "AzureCloud" // target Azure Cloud
DefaultBranch = "master" // default branch for pipeline and branch policy

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should be main right?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, we kept it as master because the original GitHub flow created a master branch. We can switch the default branch to main for both.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added an issue to track this #725

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you sure? I believe it defaults to what the developer machine has as the default and we want that default to be main.

require.NoError(t, err)
require.NotNil(t, policyType)
require.EqualValues(t, *policyType.DisplayName, "Build")

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please scribe for extra lines

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No problem, I will remove them.

Comment on lines +44 to +49
"versioncontrol": {
"sourceControlType": "git",
},
"processTemplate": {
"templateTypeId": processTemplateId,
},

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One is allower, the other is camel...consistent?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can make the adjustment, unfortunately this is an underlying api property. In a future PR we could create a struct with the json mapping comments instead of relying on the map object. This could be a contribution back to the go sdk for azure devops and the capabilities property.

Comment thread cli/azd/pkg/azdo/project.go Outdated
console.Message(ctx, fmt.Sprintf("error: the project name '%s' is already in use\n", name))
continue // try again
} else if strings.Contains(message, "The following name is not valid") {
console.Message(ctx, fmt.Sprintf("error: the project name '%s' is not a valid Azure DevOps project Name. See https://aka.ms/azure-dev/azdo-project-naming\n", name))

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make sure all akas are created and have adpteam as co-owner

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will do, I added Rajesh as co-owner but will add adpteam.

) (serviceendpoint.CreateServiceEndpointArgs, error) {
endpointType := "azurerm"
endpointOwner := "library"
endpointUrl := "https://management.azure.com/"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this overridable? Does it need to be?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes it should be . There's a few spots in the az cli package that is hard coded to this endpoint, but to support sovereign clouds, it should be overridable. I'll add an issue so we can address this.

Co-authored-by: Jon Gallant <2163001+jongio@users.noreply.github.com>
@azure-sdk

Copy link
Copy Markdown
Collaborator

Repoman Generation Results

Repoman pushed changes to remotes for the following projects:

Project: todo-csharp-cosmos-sql

Remote: azure-samples-staging

Branch: pr/693

You can initialize this project with:

azd init -t Azure-Samples/todo-csharp-cosmos-sql -b pr/693

View Changes | Compare Changes


Project: todo-csharp-sql

Remote: azure-samples-staging

Branch: pr/693

You can initialize this project with:

azd init -t Azure-Samples/todo-csharp-sql -b pr/693

View Changes | Compare Changes


Project: todo-nodejs-mongo-aca

Remote: azure-samples-staging

Branch: pr/693

You can initialize this project with:

azd init -t Azure-Samples/todo-nodejs-mongo-aca -b pr/693

View Changes | Compare Changes


Project: todo-nodejs-mongo-swa-func

Remote: azure-samples-staging

Branch: pr/693

You can initialize this project with:

azd init -t Azure-Samples/todo-nodejs-mongo-swa-func -b pr/693

View Changes | Compare Changes


Project: todo-nodejs-mongo

Remote: azure-samples-staging

Branch: pr/693

You can initialize this project with:

azd init -t Azure-Samples/todo-nodejs-mongo -b pr/693

View Changes | Compare Changes


Project: todo-nodejs-mongo-terraform

Remote: azure-samples-staging

Branch: pr/693

You can initialize this project with:

azd init -t Azure-Samples/todo-nodejs-mongo-terraform -b pr/693

View Changes | Compare Changes


Project: todo-python-mongo-aca

Remote: azure-samples-staging

Branch: pr/693

You can initialize this project with:

azd init -t Azure-Samples/todo-python-mongo-aca -b pr/693

View Changes | Compare Changes


Project: todo-python-mongo-swa-func

Remote: azure-samples-staging

Branch: pr/693

You can initialize this project with:

azd init -t Azure-Samples/todo-python-mongo-swa-func -b pr/693

View Changes | Compare Changes


Project: todo-python-mongo

Remote: azure-samples-staging

Branch: pr/693

You can initialize this project with:

azd init -t Azure-Samples/todo-python-mongo -b pr/693

View Changes | Compare Changes


Project: todo-python-mongo-terraform

Remote: azure-samples-staging

Branch: pr/693

You can initialize this project with:

azd init -t Azure-Samples/todo-python-mongo-terraform -b pr/693

View Changes | Compare Changes


@azure-sdk

Copy link
Copy Markdown
Collaborator

Azure Dev CLI Install Instructions

Install scripts

MacOS/Linux

May elevate using sudo on some platforms and configurations

bash:

curl -fsSL https://azuresdkreleasepreview.blob.core.windows.net/azd/standalone/pr/693/uninstall-azd.sh | bash;
curl -fsSL https://azuresdkreleasepreview.blob.core.windows.net/azd/standalone/pr/693/install-azd.sh | bash -s -- --base-url https://azuresdkreleasepreview.blob.core.windows.net/azd/standalone/pr/693 --version '' --verbose

pwsh:

Invoke-RestMethod 'https://azuresdkreleasepreview.blob.core.windows.net/azd/standalone/pr/693/uninstall-azd.ps1' -OutFile uninstall-azd.ps1; ./uninstall-azd.ps1
Invoke-RestMethod 'https://azuresdkreleasepreview.blob.core.windows.net/azd/standalone/pr/693/install-azd.ps1' -OutFile install-azd.ps1; ./install-azd.ps1 -BaseUrl 'https://azuresdkreleasepreview.blob.core.windows.net/azd/standalone/pr/693' -Version '' -Verbose

Windows

powershell -c "Set-ExecutionPolicy Bypass Process; irm 'https://azuresdkreleasepreview.blob.core.windows.net/azd/standalone/pr/693/uninstall-azd.ps1' > uninstall-azd.ps1; ./uninstall-azd.ps1;"
powershell -c "Set-ExecutionPolicy Bypass Process; irm 'https://azuresdkreleasepreview.blob.core.windows.net/azd/standalone/pr/693/install-azd.ps1' > install-azd.ps1; ./install-azd.ps1 -BaseUrl 'https://azuresdkreleasepreview.blob.core.windows.net/azd/standalone/pr/693' -Version '' -Verbose;"

Standalone Binary

Container

docker run -it azdevcliextacr.azurecr.io/azure-dev:pr-693

@vhvb1989

Copy link
Copy Markdown
Member

Closed in favor of: #743

@rajeshkamal5050 rajeshkamal5050 added the area/pipeline CI/CD pipeline config (GH Actions, AzDO) label Apr 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/pipeline CI/CD pipeline config (GH Actions, AzDO)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support Azure DevOps in Pipeline Commands

5 participants