I want to analyze the log of the Ansible task inside a release pipeline with a custom task extension (node). In generell this is no big thing, but I ask my self whether it is possible to get the position of my executing task inside the pipeline?
Usecase
The user could add an Ansible
task and if he want he can add my custom task to analyze the log (and publish somewhere). To decide which Ansible
task inside the release pipeline should analyzed, the user should but the custom task directly after the Ansible
task.
Something like this:
Release Pipeline 1.) Stage:
- Initialize job
- Download artifacts
- CopyFilesOverSSH
- Ansible <--- this should analyzed
- Custom Task
- Ansible
- Finialize job
Szenario
A release Pipeline with 3 Stages.
- 1.) Stage linear
- 2.) Stage & 3.) Stage parallel on second level
- all stages contains a ansible task
- all stages should contain my custom task extension to analyze the ansible task log
The Problem
When I now request the Get Release REST call I can loop though all environments, all jobs, all tasks looks like:
let release: Release = await Api.getRelease(Env.System.TeamProject, Env.Release.ReleaseId);
// loop environments (stages)
for (let environment of release.environments) {
// loop deploy steps
for (let deployStep of environment.deploySteps || []) {
// loop phases
for (let releaseDeployPhase of deployStep.releaseDeployPhases || []) {
// loop jobs
for (let deploymentJob of releaseDeployPhase.deploymentJobs || []) {
let ansible: ReleaseTask[] = [];
// loop tasks
for (let task of deploymentJob.tasks || []) {
if (task.startTime && task.finishTime) {
if (task.name === "Ansible") ansible.push(task);
}
}
console.log(ansible);
}
}
}
}
on runtime on this state my executing custom task is not finished yet (TaskStatus.InProgress
), so together with the id of my task I am should able to detect the position inside the pipeline.
Some better Solution?
But I hope there is a much better solution, I mean the task should know which position it has inside the pipeline or? Maybe there is an information you can get over the azure-pipelines-task-lib/task lib?
Something like:
task.getRank() >>> 3
task.getEnvironment >>> 2
What also could help is when you could request the task name and the id inside the task program. Currently I have to create own variables with these information.
Something like this:
me.Id() >>> "8bb50e0a-8efb-47a4-b12a-2190f3a4d16a"
me.Name() >>> "MyCustomTask"