dmitryserbin / azdev-release-orchestrator

Azure DevOps extension to manage and orchestrate release pipelines
MIT License
23 stars 13 forks source link

OrchestratorV2 throws error if definitionName is classic pipeline definition ID number #93

Open matteopessina opened 1 year ago

matteopessina commented 1 year ago

Hi Dimitry, first of all, thank you for this extension: It is very useful.

Context: I have a YAML pipeline which use the orchestrator@2 task to approve a release in a classic release pipeline.

According to specification, definition name can be also the ID of the pipeline.

Tasks/OrchestratorV2/task.json

{
  "name": "definitionName",
  "type": "pickList",
  "label": "Definition name",
  "helpMarkDown": "Target release definition name or ID",
  "required": true,
  "properties": {
    "EditableOptions": true
  }
}

If the numeric ID of the pipeline is passed as an argument the task fails.

2023-06-08T16:25:10.093Z release-orchestrator:TaskHelper:getParameters { releaseType: 'Specific',
  projectName: '<OMITTED>',
  definitionName: '443',
  releaseName: '0.84.230531.1-R1',
  stages: [ 'Tier2' ],
  variables: [],
  filters:
   { releaseTags: [],
     artifactTags: [],
     artifactVersion: '',
     artifactBranch: '',
     stageStatuses: [] },
...
release-orchestrator:Retry:retryable Executing <getReleaseDefinitions> with <10> retries
release-orchestrator:ReleaseHelper:getDefinition []
release-orchestrator:TaskHelper:fail Task <Failed> result (ignore failure <false>)
##[debug]task result: Failed
##[error]Definition <443> not found

I searched in the code and the issue could be in Tasks/OrchestratorV2/helpers/releasehelper.ts

public async getDefinition(projectName: string, definitionName: string): Promise<ReleaseDefinition> {

    const debug = this.debugLogger.extend(this.getDefinition.name);

    const matchingDefinitions: ReleaseDefinition[] = await this.releaseApi.getReleaseDefinitions(
        projectName,
        definitionName,
        undefined,
        undefined,
        undefined,
        undefined,
        undefined,
        undefined,
        undefined,
        true);

    debug(matchingDefinitions.map(
        (definition) => `${definition.name} (${definition.id})`));

    if (matchingDefinitions.length <= 0) {

        throw new Error(`Definition <${definitionName}> not found`);

    }

    const targetDefinition: ReleaseDefinition = await this.releaseApi.getReleaseDefinition(
        projectName,
        matchingDefinitions[0].id!);

    debug(targetDefinition);

    return targetDefinition;

}

In case you would like code contribution, I am interested in working together for a solution.

Best Matteo

dmitryserbin commented 1 year ago

Thanks for using Orchestrator! This sounds like a bug, and I'm sure can be fixed.

ADO API allows filtering release search by ID, so we could: detect whether definitionName parameter value is an ID, and then conditionally pass it to getReleaseDefinitions function as definitionIdFilter parameter.

Feel free to play with it and submit a PR.