BeGreen
BeGreen

Reputation: 951

Use Azure DevOps pipelines for multiples git projects and dynamic arguments

What I'm trying to achieve is to run a Azure DevOps pipeline for all my repos.

This pipeline aims to sync Azure Repos to a legacy GitLab. Some tools cannot acces to Azure's git. But our pool can acces our azure git and gitlab.

Also, I'd like it to be triggered on all branches and git projects and taking git/branch names of the project when a commit is done.

pool:
  name: -----
  demands:
   - agent.name -equals --------


parameters:
- name: git_repo
  displayName: Git Repo Name
  type: string
- name: git_branch
  displayName: Git Branch Name
  type: string

steps:

- task: AzureKeyVault@2
  inputs:
    azureSubscription: '--------'
    KeyVaultName: '------'
    SecretsFilter: 'gitlab-token, azure-devops-token'
    RunAsPreJob: false

- task: ShellScript@2
  env:
      GITLAB_TOKEN: $(gitlab-token)
      AZUREDEVOPS_TOKEN: $(azure-devops-token)
  inputs:
    scriptPath: '$(Build.SourcesDirectory)/sync_gitlab/scripts/sync_gitlab.sh'
    args: '${{ parameters.git_repo }} ${{ parameters.git_branch }}'

At the moment I am only able to create a manual pipeline that takes git repo name and a branch name. Any idea on how to create this "wildcard" trigger accross all repos without dropping the yaml file across all branches/projects?

FYI $(Build.SourcesDirectory)/sync_gitlab/scripts/sync_gitlab.sh is just a simple bash script that git pull the Azure repos with a Azure Token from Azure keyvault, checkout on the branch given in input, then set-url for the gitlab remote url and force push the branch.

Upvotes: 0

Views: 282

Answers (1)

Bowman Zhu
Bowman Zhu

Reputation: 7251

Any idea on how to create this "wildcard" trigger accross all repos without dropping the yaml file across all branches/projects?

Is the project you mentioned here a concept in DevOps?

If so, you must notice that if you want the YAML file work, you must make sure the yaml exists in each branch if you want to make it work in that branch.

I notice you are trying to get repository name and branch name at compile time.

For repository name, there is no way to auto get the value at compile time. Because Build.Repository.Name is not available in template(this means this value can't access at compile time.).

For branch name, there is a predefined variable to get this value:

Build.SourceBranchName

See predefined variables.

Upvotes: 0

Related Questions