azure-devops-extension-api - Run pipeline - azure-devops

I'm trying to run a pipeline from an Azure DevOps hub extension, using the azure-devops-extension-api.
The azure-devops-extension-api (GitHub repository) contains several rest client classes, such as the BuildRestClient class and the ReleaseRestClient class. Both of which I've successfully used methods from.
However, the azure-devops-extension-api doesn't contain any rest client class for the Runs - Run Pipeline Azure DevOps Services REST API. I'm suspecting that this is because this endpoint is new for the 6.0 version of the API, and so it hasn't been implemented in the azure-devops-extension-api yet
Is there any way that I could use this azure-devops-extension-api to run a specified pipeline?
Perhaps via the queueBuild method? I want to run a specific pipeline though, not a specific old build.
Any input would be appreciated!

What I ended up doing, was creating my own PipelineClient class (from the Runs - Run Pipeline), which extends the RestClientBase from the azure-devops-extension-api/Common/RestClientBase.
Thankful for the input I got to this question, it's appreciated!

Yes, if you want to use azure-devops-extension-api to run a specified pipeline, you can use queueBuild method.
Regarding the sourceBuildId parameter, there is no specific description in the document, I will add it here.
sourceBuildId: The source build must be a pull request build if queueing with sourceBuildId.

Related

Renaming Azure Devops Build and Release pipeline through REST API

trying to rename the pipelines build and release through REST API, I have gone through the official Microsoft documentation but didn't find any API's for this task. Did i miss any or we have such API's where by using build id/build name we can rename the pipeline
have you tried to make the change in the azure release page and look at the request that is being sent in the dev tools network tab? A couple of months ago I was able to learn how to retrieve some information that I was looking for by doing that.
Best regards.
You could use Definitions-Get API to retrieve the requested body by pipeline definition ID.
Copy the response as body and use Definitions-Update to rename the pipeline. Update the pipeline name of this revision.
Check the DevOps UI output.
The above workflow also applies to release pipeline, your need to change the REST API.
Using Releases-Get release to get the latest revision and using Releases - Update Release to rename it

Azure DevOps - Find pipelines with schedules

In Azure DevOps, when trying to find all jobs with time based triggers, is there an alternative to examining them one by one using UI or CLI?
You can try to use Rest API to list builds.
GET https://dev.azure.com/{organization}/{project}/_apis/build/builds?reasonFilter=schedule&api-version=6.1-preview.6
After adding reasonFilter=schedule parameter, you will get all schedule triggered builds and information related to the builds such as definition ids.

How can you convert a GitHub action that uses Docker images into Azure Pipelines custom task

I'm trying to create a custom task to be published on the Azure Pipelines Marketplace so that people can use my security tool within Azure Pipelines. The task requires a lot of additional software, so Docker has been used for packaging.
I've similarly created the action for GitHub Actions, https://github.com/tonybaloney/pycharm-security/blob/master/action.yml
The action will-
Use a custom Docker image (hosted on Docker Hub)
Mount the code after checkout
Run a custom entry point, passing the arguments provided to the action
I cannot see how to achieve the same thing in Azure Pipelines. All of the example code for custom tasks is written in TS/Node or PowerShell.
The only TS/Node.js example doesn't show you how to do anything like download a docker image and run it.
The only other documentation I can find is about how to build a Docker image from within a Pipeline. But I want to download and run an image as a Task.
The Task SDK documentation clearly shows how to construct the package, but not how to do anything beyond getting it to pass arguments.
One possibility is to clone the DockerV2 Task and to customize it to run the Docker commands that I need, but this seems quite convoluted compared with how simple it is in GitHub Actions
How can you convert a GitHub action that uses Docker images into Azure Pipelines custom task
I am afraid you have to clone the DockerV2 Task and to customize it to run the Docker commands that you need.
The reason for its complexity is that their implementation forms are different.
We are customizing github action and publishing to Marketplace, the custom github action did not compile and package the source code, but just quoted the original code. In other words, our custom action is more like providing a link to tell the compiler where to download the source code and pass parameters and rewrite the source code. So we don't need to download the source code of github action and customize it.
However, the Azure Pipelines custom task is different. The custom task needs to be compiled to generate a .visx file, which requires the source code and compiles it after rewriting.
Besides, Azure devops provide a Task groups, so that we could encapsulate a sequence of tasks, already defined in a build or a release pipeline, into a single reusable task that can be added to a build or release pipeline, just like any other task. You can choose to extract the parameters from the encapsulated tasks as configuration variables, and abstract the rest of the task information.
Hope this helps.

How to create new build pipeline using Azure DevOps REST API?

I'm trying to create new build pipeline through programmatically. I'm looking for Azure DevOps REST API for this action. I didn't get the proper examples for creating the pipeline using REST API.
Please advise.
How to create new build pipeline using Azure DevOps REST API?
To create the new build pipeline, we could use the REST API Definitions - Create:
POST https://dev.azure.com/{organization}/{project}/_apis/build/definitions?api-version=5.0
But we need provide too much information in the Request Body, this will be a big project and error-prone. That also the reason why the document not provide a sample Request Body there.
To resolve this issue, usually we would use the REST API Definitions - Get to get the Response Body from the template pipeline:
GET https://dev.azure.com/{organization}/{project}/_apis/build/definitions/{definitionId}?api-version=5.0
Then we just need to update the corresponding properties by modifying the Response Body.
Now, we get the new Request Body for the new pipeline, we could use it with REST API Definitions - Create to create a new pipeline.
You could check this thread for some more details.
Update:
After creating the build definition, Will it create
azure-pipelines.yml file and store in the repository like Azure Repos?
No, if you want to create a YAML type build definition using the rest api, it will not create the corresponding yaml file to our repo, because this API Definitions - Create only send the request body to the pipeline does not operate our repo. Currently, it support creating a build definition that links to a YAML file within the Git repo. If you want to create the yaml automatically, you could check the REST API Pushes - Create.
This should be where the REST API Definitions - Create needs to be improved to support the YAML pipeline. You could add your request for this feature on our UserVoice site (https://developercommunity.visualstudio.com/content/idea/post.html?space=21 ), which is our main forum for product suggestions. Thank you for helping us build a better Azure DevOps:
Hope this helps.

How to configure Azure DevOps Pipeline decorators to run pre-tasks in classic pipelines?

We have a custom Azure DevOps extension to in order to inject SonarQube pipeline tasks into every definition using the Pipeline Decorator feature. These tasks are a mixutre of both pre and post tasks.
In YAML defined pipelines, the tasks run perfectly, however in Classic pipeline definitions, only the post tasks run, although the classic and YAML pipelines are defined identically (steps, agents, demands, variables etc.).
As this is a relatively new feature of Azure DevOps, there is a lack of documentation, especially regarding classic pipelines.
Is there something that we could possibly be missing for this to happen?
Is there something that we could possibly be missing for this to
happen?
This seems the issue on our side. And, it only exists to the sonarcloud/sonarqube prepare task if we apply it into Decorator.
As you know, users use yaml template for the steps to inserted at the specified location. And in fact, on our backend, this template file is processed through yaml template engine.
As our design, after you enable the Pipeline decorators at organization level. In Initialize job, Pipeline will call one backend class to get the JobContext, which will add decorator providers to JobContext. Then JobContext use these providers to fetch contributions to add pre/post tasks in job while preparing the job to run.
BUT, the sonar prepare task can not actively be detected by engine, then inject it into JobContext. For why I point to this specific task, because this kind of abnormality only exists in the prepare task of sonarcloud and sonarqube until now.
Our team will do some investigation and fix with sonar team together.
Until now, there has 2 work around you could consider to apply.
Work around 1:
As I mentioned previously, this prepare task can not actively be detected and injected into JobContext. So, the first work around we actively add this task info into JobContext via adding prepare task into agent job.
But this will cause one disadvantage is, it will load 2 prepare tasks. One is executed in pre-job, and next it will run second.
Work around 2:
Try to use YAML to build your pipeline until we implement this abnormality thing. So that it will not cause error because of lacking prepare task
Will update the status here to let you know once we have any progress.