This is the repo that will contain the code for our super custom devops servicenow plugin.
TODO: Guide users through getting your code up and running on their own system. In this section you can talk about:
- Installation process
- Software dependencies
- Latest releases
- API references
(New Task Docs)[https://learn.microsoft.com/en-us/azure/devops/extend/develop/add-build-task?view=azure-devops]
Create a new tasks
folder in the root directory, and another folder inside of it for your task eg mynewtask
mkdir -p tasks/mynewtask
cd into the new directory and create the task scaffolding
cd tasks/mynewtask
npm init --yes
npm install azure-pipelines-task-lib --save
npm install @types/node --save-dev
npm install @types/q --save-dev
echo node_modules > .gitignore
npm install mocha --save-dev -g
npm install sync-request --save-dev
npm install @types/mocha --save-dev
npm install typescript@4.6.3 -g --save-dev
tsc --init --target esnext
touch task.json
touch index.ts
Create a task.json file in the mynewtask folder. Copy the following code and replace the {{placeholders}} with your task's information. The most important placeholder is the taskguid, and it must be unique.
{
"$schema": "https://raw.githubusercontent.com/Microsoft/azure-pipelines-task-lib/master/tasks.schema.json",
"id": "{{taskguid}}",
"name": "{{taskname}}",
"friendlyName": "{{taskfriendlyname}}",
"description": "{{taskdescription}}",
"helpMarkDown": "",
"category": "Utility",
"author": "{{taskauthor}}",
"version": {
"Major": 0,
"Minor": 1,
"Patch": 0
},
"instanceNameFormat": "Echo $(samplestring)",
"inputs": [
{
"name": "samplestring",
"type": "string",
"label": "Sample String",
"defaultValue": "",
"required": true,
"helpMarkDown": "A sample string"
}
],
"execution": {
"Node": {
"target": "index.js"
}
}
}
Create an index.ts file by using the following code as a reference. This code runs when the task gets called.
import tl = require('azure-pipelines-task-lib/task');
async function run() {
try {
const inputString: string | undefined = tl.getInput('samplestring', true);
if (inputString == 'bad') {
tl.setResult(tl.TaskResult.Failed, 'Bad input was given');
return;
}
console.log('Hello', inputString);
}
catch (err) {
tl.setResult(tl.TaskResult.Failed, err.message);
}
}
run();
Create a tests folder containing a _suite.ts file with the following contents:
import * as path from 'path';
import * as assert from 'assert';
import * as ttm from 'azure-pipelines-task-lib/mock-test';
describe('Sample task tests', function () {
before( function() {
});
after(() => {
});
it('should succeed with simple inputs', function(done: Mocha.Done) {
// Add success test here
});
it('it should fail if tool returns 1', function(done: Mocha.Done) {
// Add failure test here
});
});
Create a success.ts file in your test directory with the following contents.
import ma = require('azure-pipelines-task-lib/mock-answer');
import tmrm = require('azure-pipelines-task-lib/mock-run');
import path = require('path');
let taskPath = path.join(__dirname, '..', 'index.js');
let tmr: tmrm.TaskMockRunner = new tmrm.TaskMockRunner(taskPath);
tmr.setInput('samplestring', 'human');
tmr.run();
Create a failure.ts file in your test directory with the following contents.
import ma = require('azure-pipelines-task-lib/mock-answer');
import tmrm = require('azure-pipelines-task-lib/mock-run');
import path = require('path');
let taskPath = path.join(__dirname, '..', 'index.js');
let tmr: tmrm.TaskMockRunner = new tmrm.TaskMockRunner(taskPath);
tmr.setInput('samplestring', 'bad');
tmr.run();
cd into the task directory and install the dependenceiew
npm install
Enter "tsc" from the task folder to compile an index.js file from index.ts.
tsc
You can now run the compiles task with: (note that you may have top add a few env variables to simulate the task inputs if you have any, eg. INPUT_SAMPLESTRING="Human")
node index.js
If the test files and frameworks have beenm created insite the test folder you can run the tests:
tsc
mocha tests/_suite.js
you want to run the tests with more verbose output (what you'd see in the build console), set the environment variable: TASK_TEST_TRACE=1.
export TASK_TEST_TRACE=1
TODO: Explain how other users and developers can contribute to make your code better.
If you want to learn more about creating good readme files then refer the following guidelines. You can also seek inspiration from the below readme files:
/ deploy test tfx extension publish --manifest-globs vss-extension.json vss-extension-test.json // deploy release tfx extension publish --manifest-globs vss-extension.json vss-extension-release.json