Reputation: 65
I am working on an Azure DevOps setup where each repository is located in a different project. I created an environment (e.g., Production
) in one project to manage deployments on a virtual machine (VM). However, when I try to access this environment from a repository in another project, I encounter issues like the environment not being visible or accessible.
Production
in Project A within Repository A and added a VM (MyResource
) as a resource.Production
) in Project B for a pipeline in Repository B, targeting the same VM (MyResource
).Production
environment. It seems I would need to recreate the environment in each project, which duplicates the setup unnecessarily.Production
) across multiple repositories located in different Azure DevOps projects.MyResource
) without duplicating environments or agents.Here’s a simplified version of the YAML pipeline in Repository B:
jobs:
- deployment: DeployToVM
displayName: 'Deploy to VM'
environment:
name: 'Production' # Environment created in Project A
resourceName: 'MyResource'
resourceType: VirtualMachine
strategy:
runOnce:
deploy:
steps:
- script: echo "Deploying to shared VM"
Production
environment exists in the Environments section of Project A.Upvotes: 0
Views: 100
Reputation: 5522
Your description of "created an environment Production
in Repository A" and "access this environment from another repository" is not quite accurate.
The environment is not created or used in the repository, but in the pipeline.
Pipelines in the same project can use the environment in the current project by modifying the pipeline permissions, no matter which repository the pipeline is using. A project can have many repositories.
Therefore, your question should probably be changed to "How to Share Azure DevOps Environment Across Multiple Projects for Deployment?"
However, currently Environment cannot be shared between projects. You can request the feature for Azure DevOps here to help the feature better.
Workaround 1:
You can consider using the deployment group of the classic release pipeline. Deployment groups are available only for Classic release pipelines.
You can share deployment groups with other projects in the organization.
If you can't find the where to create the classic release pipeline, you can enable creation of classic pipelines by toggling the option at the organization level or project level.
For example, to enable it at the organization level, navigate to your organization settings > select Settings > turn off Disable creation of classic release pipelines.
Workaround 2:
Create the pipelines in the project where the environment is created and check out repositories from other projects in the pipeline.
For example:
resources:
repositories:
- repository: B
type: git
name: ProjectBName/RepoName
ref: main
trigger:
- main
jobs:
- deployment: DeployToVM
displayName: 'Deploy to VM'
environment:
name: 'Production' # Environment created in Project A
resourceName: 'MyResource'
resourceType: VirtualMachine
strategy:
runOnce:
deploy:
steps:
# - checkout: self
- checkout: B
- script: echo "Deploying to shared VM"
This way, we only need to create the environment with VM Resource in one project.
Upvotes: 1