
by BoxBoat
Performs actions in Azure DevOps.
README
Secrets
accesstoken
– Your personal access token (PAT) from Azure DevOps.
Variables
org
– Your organization in Azure DevOps where your pipeline resides.project
– The project in Azure DevOps where your pipeline resides (i.e. must be inside the org).
Additional Configuration
In the SelectPipeline()
method, set each case
name and the id
used inside the case to call the TriggerPipeline(int)
method. For example:
case "<your app name>":
await TriggerPipeline(<the id of the pipeline that builds this application>);
break;
If you can’t find your pipeline id, navigate to the pipeline in your browser and look at the URL. It should have a query parameter with something like: definitionId=xx
.
Known limitations:
- This only supports pipelines living in a single org/project currently.
Usage
@az pipeline app1 – Triggers the pipeline for app1
Code
// get a personal access token (PAT) from Azure DevOps
// and place it in your secrets as “accesstoken”.
string accesstoken = await Bot.Secrets.GetAsync(“accesstoken”);
string baseUri = $”https://dev.azure.com/{org}/{project}/_apis/build/builds?api-version=6.0″;
string creds = System.Convert.ToBase64String(ASCII.GetBytes($”:{accesstoken}”));
Headers headers = new Headers {{“Authorization”, “Basic “+ creds}};
// Effectively the starting point of our skill.
var (command, argument) = Bot.Arguments;
await CommandSelector();
/////////////////////////////Supporting Methods/////////////////////////////
// if you want to do more with Azure DevOps, (interact with work items, etc…)
// add more top-level commands here.
public async Task CommandSelector()
{
switch (command.Value)
{
case “pipeline”:
await SelectPipeline();
break;
default:
await Bot.ReplyAsync(“¯\\_(ツ)_/¯ I don’t understand that command!”);
break;
}
}
/////////
// Routes request to the appropriate app pipeline
/////////
public async Task SelectPipeline()
{
switch (argument.Value)
{
// rename your apps for each case. this is what defines
// the app name when calling the skill. (ex. “build app1”)
case “app1”:
// set the pipeline definition id for this app here
await TriggerPipeline(38);
break;
case “app2”:
// await TriggerPipeline(<pipelineId>);
await Bot.ReplyAsync(“You haven’t created app2 yet. Chop chop!”);
break;
default:
await Bot.ReplyAsync(“¯\\_(ツ)_/¯ I don’t know that app!”);
break;
}
}
/////////
// Calls Azure DevOps to trigger the specified pipeline.
/////////
public async Task TriggerPipeline(int pipelineId)
{
var requestUri = $”{baseUri}&definitionId={pipelineId.ToString()}”;
var response = await Bot.Http.PostJsonAsync(requestUri, “”, headers);
await Bot.ReplyAsync($”Okay, you got it. {argument.Value} has been triggered.”);
}
Version History
Version | Created | Author | Release Notes | Installs |
---|---|---|---|---|
1.0.0 | 2/25/2021 |
![]() Justin VanWinkle |
Initial Release. Provides the ability to trigger pipelines in Azure DevOps. |
2 |
You need an account to install this package with Abbot. Signing in with Slack or Discord will create an account if you don’t have one already.
Details
-
Last updated -
Installs - 2 total installs
-
Language - CSharp
-
License - MIT License