A cross platform agent OR a TFS 2015 Update 2 Windows agent (or higher) is required to run a Node task end-to-end. However, an agent is not required for interactively testing the task.
For now, the built azure-pipelines-task-lib (in _build) should be packaged with your task in a node_modules folder
The build generates a azure-pipelines-task-lib.d.ts file for use when compiling tasks In the example below, it is in a folder named definitions above the tasks lib
/// <reference path="../definitions/azure-pipelines-task-lib.d.ts" />
import tl = require('azure-pipelines-task-lib/task')
Input Functions (v)
getInput
getBoolInput
getPathInput
filePathSupplied
getDelimitedInput
getVariable
VariableInfo
getVariables
setVariable
getTaskVariable
setTaskVariable
Execution (v)
tool
ToolRunner.arg
ToolRunner.line
ToolRunner.argIf
IExecOptions
ToolRunner.exec
ToolRunner.execSync
ToolRunner.pipeExecOutputToTool
IExecSyncResult
exec
execSync
setResult
Service Connections (v)
getEndpointUrl
getEndpointDataParameter
getEndpointAuthorizationScheme
getEndpointAuthorizationParameter
EndpointAuthorization
getEndpointAuthorization
Secrets (v)
Secure Files (v)
getSecureFileName
getSecureFileTicket
Disk Functions (v)
which
checkPath
exist
cd
cp
mv
mkdirP
FindOptions
find
rmRF
pushd
popd
resolve
stats
writeFile
Globbing (v)
MatchOptions
match
findMatch
filter
legacyFindFiles
Localization (v)
Proxy (v)
Functions for retrieving inputs for the task
task.getInput (^)
Gets the value of an input. The value is also trimmed. If required is true and the value is not set, it will throw.
@returns string
getInput(name:string, required?:boolean):string
Param | Type | Description |
---|---|---|
name | string | name of the input to get |
required | boolean | whether input is required. optional, defaults to false |
task.getBoolInput (^)
Gets the value of an input and converts to a bool. Convenience. If required is true and the value is not set, it will throw.
@returns string
getBoolInput(name:string, required?:boolean):boolean
Param | Type | Description |
---|---|---|
name | string | name of the bool input to get |
required | boolean | whether input is required. optional, defaults to false |
task.getPathInput (^)
Gets the value of a path input It will be quoted for you if it isn't already and contains spaces If required is true and the value is not set, it will throw. If check is true and the path does not exist, it will throw.
@returns string
getPathInput(name:string, required?:boolean, check?:boolean):string
Param | Type | Description |
---|---|---|
name | string | name of the input to get |
required | boolean | whether input is required. optional, defaults to false |
check | boolean | whether path is checked. optional, defaults to false |
task.filePathSupplied (^)
Checks whether a path inputs value was supplied by the user File paths are relative with a picker, so an empty path is the root of the repo. Useful if you need to condition work (like append an arg) if a value was supplied
@returns boolean
filePathSupplied(name:string):boolean
Param | Type | Description |
---|---|---|
name | string | name of the path input to check |
task.getDelimitedInput (^)
Gets the value of an input and splits the value using a delimiter (space, comma, etc). Empty values are removed. This function is useful for splitting an input containing a simple list of items - such as build targets. IMPORTANT: Do not use this function for splitting additional args! Instead use argString(), which follows normal argument splitting rules and handles values encapsulated by quotes. If required is true and the value is not set, it will throw.
@returns string[]
getDelimitedInput(name:string, delim:string, required?:boolean):string[]
Param | Type | Description |
---|---|---|
name | string | name of the input to get |
delim | string | delimiter to split on |
required | boolean | whether input is required. optional, defaults to false |
task.getVariable (^)
Gets a variable value that is defined on the build/release definition or set at runtime.
@returns string
getVariable(name:string):string
Param | Type | Description |
---|---|---|
name | string | name of the variable to get |
task.VariableInfo (^)
Snapshot of a variable at the time when getVariables was called.
Property | Type | Description |
---|---|---|
name | string | |
value | string | |
secret | boolean |
task.getVariables (^)
Gets a snapshot of the current state of all job variables available to the task. Requires a 2.104.1 agent or higher for full functionality.
Limitations on an agent prior to 2.104.1:
- The return value does not include all public variables. Only public variables that have been added using setVariable are returned.
- The name returned for each secret variable is the formatted environment variable name, not the actual variable name (unless it was set explicitly at runtime using setVariable).
@returns VariableInfo[]
getVariables():VariableInfo[]
task.setVariable (^)
Sets a variable which will be available to subsequent tasks as well.
@returns void
setVariable(name:string, val:string, secret?:boolean):void
Param | Type | Description |
---|---|---|
name | string | name of the variable to set |
val | string | value to set |
secret | boolean | whether variable is secret. Multi-line secrets are not allowed. Optional, defaults to false |
task.getTaskVariable (^)
Gets a variable value that is set by previous step from the same wrapper task. Requires a 2.115.0 agent or higher.
@returns string
getTaskVariable(name:string):string
Param | Type | Description |
---|---|---|
name | string | name of the variable to get |
task.setTaskVariable (^)
Sets a task variable which will only be available to subsequent steps belong to the same wrapper task. Requires a 2.115.0 agent or higher.
@returns void
setTaskVariable(name:string, val:string, secret?:boolean):void
Param | Type | Description |
---|---|---|
name | string | name of the variable to set |
val | string | value to set |
secret | boolean | whether variable is secret. optional, defaults to false |
Tasks typically execute a series of tools (cli) and set the result of the task based on the outcome of those
/// <reference path="../definitions/azure-pipelines-task-lib.d.ts" />
import tl = require('azure-pipelines-task-lib/task');
import tr = require('azure-pipelines-task-lib/toolrunner');
try {
var toolPath = tl.which('atool');
var atool:tr.ToolRunner = tl.tool(toolPath).arg('--afile').line('arguments');
var code: number = await atool.exec();
console.log('rc=' + code);
}
catch (err) {
tl.setResult(tl.TaskResult.Failed, err.message);
}
task.tool (^)
Convenience factory to create a ToolRunner.
@returns ToolRunner
tool(tool:string):ToolRunner
Param | Type | Description |
---|---|---|
tool | string | path to tool to exec |
toolrunner.ToolRunner.arg (^)
Add argument Append an argument or an array of arguments returns ToolRunner for chaining
@returns ToolRunner
arg(val:string | string[]):ToolRunner
Param | Type | Description |
---|---|---|
val | string | string[] | string cmdline or array of strings |
toolrunner.ToolRunner.line (^)
Parses an argument line into one or more arguments e.g. .line('"arg one" two -z') is equivalent to .arg(['arg one', 'two', '-z']) returns ToolRunner for chaining
@returns ToolRunner
line(val:string):ToolRunner
Param | Type | Description |
---|---|---|
val | string | string argument line |
toolrunner.ToolRunner.argIf (^)
Add argument(s) if a condition is met Wraps arg(). See arg for details returns ToolRunner for chaining
@returns ToolRunner
argIf(condition:any, val:any):this
Param | Type | Description |
---|---|---|
condition | any | boolean condition |
val | any | string cmdline or array of strings |
toolrunner.IExecOptions (^)
Interface for exec options
Property | Type | Description |
---|---|---|
failOnStdErr | boolean | optional. whether to fail if output to stderr. defaults to false |
ignoreReturnCode | boolean | optional. defaults to failing on non zero. ignore will not fail leaving it up to the caller |
toolrunner.ToolRunner.exec (^)
Exec a tool. Output will be streamed to the live console. Returns promise with return code
@returns number
exec(options?:IExecOptions):any
Param | Type | Description |
---|---|---|
options | IExecOptions | optional exec options. See IExecOptions |
toolrunner.ToolRunner.execSync (^)
Exec a tool synchronously. Output will be not be streamed to the live console. It will be returned after execution is complete. Appropriate for short running tools Returns IExecSyncResult with output and return code
@returns IExecSyncResult
execSync(options?:IExecSyncOptions):IExecSyncResult
Param | Type | Description |
---|---|---|
options | IExecSyncOptions | optional exec options. See IExecSyncOptions |
toolrunner.ToolRunner.pipeExecOutputToTool (^)
Pipe output of exec() to another tool @returns {ToolRunner}
pipeExecOutputToTool(tool:ToolRunner, file?:string):ToolRunner
Param | Type | Description |
---|---|---|
tool | ToolRunner | |
file | string | optional filename to additionally stream the output to. |
toolrunner.IExecSyncResult (^)
Interface for exec results returned from synchronous exec functions
Property | Type | Description |
---|---|---|
stdout | string | standard output |
stderr | string | error output |
code | number | return code |
error | Error | Error on failure |
task.exec (^)
Exec a tool. Convenience wrapper over ToolRunner to exec with args in one call. Output will be streamed to the live console. Returns promise with return code
@returns number
exec(tool:string, args:any, options?:IExecOptions):any
Param | Type | Description |
---|---|---|
tool | string | path to tool to exec |
args | any | an arg string or array of args |
options | IExecOptions | optional exec options. See IExecOptions |
task.execSync (^)
Exec a tool synchronously. Convenience wrapper over ToolRunner to execSync with args in one call. Output will be not be streamed to the live console. It will be returned after execution is complete. Appropriate for short running tools Returns IExecResult with output and return code
@returns IExecSyncResult
execSync(tool:string, args:string | string[], options?:IExecSyncOptions):IExecSyncResult
Param | Type | Description |
---|---|---|
tool | string | path to tool to exec |
args | string | string[] | an arg string or array of args |
options | IExecSyncOptions | optional exec options. See IExecSyncOptions |
task.setResult (^)
Sets the result of the task. Execution will continue. If not set, task will be Succeeded. If multiple calls are made to setResult the most pessimistic call wins (Failed) regardless of the order of calls.
@returns void
setResult(result:TaskResult, message:string):void
Param | Type | Description |
---|---|---|
result | TaskResult | TaskResult enum of Succeeded, SucceededWithIssues or Failed. |
message | string | A message which will be logged as an error issue if the result is Failed. |
Retrieve service connections (previously called "service endpoints") and authorization details
task.getEndpointUrl (^)
Gets the url for a service endpoint If the url was not set and is not optional, it will throw.
@returns string
getEndpointUrl(id:string, optional:boolean):string
Param | Type | Description |
---|---|---|
id | string | name of the service endpoint |
optional | boolean | whether the url is optional |
task.getEndpointDataParameter (^)
getEndpointDataParameter(id:string, key:string, optional:boolean):string
Param | Type | Description |
---|---|---|
id | string | |
key | string | |
optional | boolean |