azure-devops-cli-extension icon indicating copy to clipboard operation
azure-devops-cli-extension copied to clipboard

[Feature Request] az pipeline run --resources (for multi repo checkout)

Open neoswallow opened this issue 2 years ago • 4 comments

Is your feature request related to a problem? Please describe. With Web GUI for the pipelines run, I can select branch/commit on each additional repo being checked out under resources section but I don't see a way to do that from the cli.

Describe the solution you'd like I want to be able to choose branch/commit on each additional repo to check out.

neoswallow avatar May 20 '22 13:05 neoswallow

Do we have any ETA on this feature request? It will be really helpful to get this feature working so we can send information about multiple repos in the request. We have Linux build pipeline in azure devops project which needs multiple repos from multiple projects. We use az pipeline run but are not able to send multiple repository information because of the current limitation.

yogeshbirla avatar Aug 01 '22 12:08 yogeshbirla

Agree it'd be very useful to be able to specify resources during scheduling a new run from Azure CLI.

kubarom avatar Dec 12 '22 17:12 kubarom

As a workaround, one can query this Azure DevOps API via curl, as suggested here as specify the desired pipeline resource.

HOST='https://hostname.com:8443/tfs'
DEVOPS_ORG='MyOrg'
DEVOPS_PROJECT='MyProject'
DEVOPS_PAT=asdasd1236secretazuredevopstoken
PIPELINE_ID=123456

curl \
    -X POST \
    "${HOST}/${DEVOPS_ORG}/${DEVOPS_PROJECT}/_apis/pipelines/${PIPELINE_ID}/runs?api-version=6.0-preview.1" \
    -H "Content-Type: application/json" \
    -u "${DEVOPS_PAT}": \
    -d @<(cat <<EOF
{
    "stagesToSkip": [],
    "resources": {
        "repositories": {
            "self": {
                "refName": "refs/heads/pipeline-yaml-definition-branch-name"
            }
        },
        "pipelines": {
            "ResourcePipeline1": {
                "version": "8.54"
            },
            "ResourcePipeline2": {
                "version": "3.14"
            }
        }
    },
    "templateParameters": {
        "parameter1": "value1",
        "parameter2": "value2",
    },
    "variables": {
        "system.debug": {
            "value": "true"
        }
    }
}
EOF
)

frazar avatar Apr 15 '24 12:04 frazar

This can also be done with az devops invoke

az devops invoke \
  --area pipelines \
  --organization https://dev.azure.com/<ORG_NAME> \
  --route-parameters project=<PROJECT_NAME> pipelineId=<PIPELINE_ID> \
  --resource runs \
  --api-version=7.2-preview \
  --http-method=post \
  --in-file=req.json

req.json

{
  "stagesToSkip": [],
  "resources": {
    "repositories": {
      "self": {
        "refName": "refs/heads/<BRANCH_NAME>"
      }
    }
  }
}

You can find documentation for the request JSON payload here: https://learn.microsoft.com/en-us/rest/api/azure/devops/pipelines/runs/run-pipeline?view=azure-devops-rest-7.2

szszoke avatar Apr 17 '24 15:04 szszoke