Coder Social home page Coder Social logo

microsoft / azure-pipelines-task-lib Goto Github PK

View Code? Open in Web Editor NEW
400.0 100.0 265.0 17.11 MB

Libraries for writing VSTS and TFS build tasks

Home Page: https://aka.ms/tfbuild

License: MIT License

JavaScript 2.14% TypeScript 67.47% PowerShell 29.10% Shell 0.02% Batchfile 0.02% C# 1.26% HTML 0.01%

azure-pipelines-task-lib's Introduction

Azure Pipelines Task SDK

Libraries for writing Azure Pipelines tasks

Reference examples of our in the box tasks are here

Status

Build & Test
Win-x64 Windows Build & Test
macOS macOS Build & Test
Linux-x64 Linux Build & Test

Highlights

  • Breaks coupling with agent: This lib is decoupled and ships with the task and the agent is just an engine to run tasks.
  • Testability: Aims to offer the ability to actually run your task scripts under all scenarios without a server or an agent.
  • Localization: The lib provides a mechanism for storing your localized strings with your task, and loading the correct set at run-time.
  • Consistent API: The TypeScript and PowerShell libs are largely consistent. They only differ where it makes sense (being true to the platform).
  • Tracing for free: Tracing has been built-in to many of the commands. Use the SDK and get some debug tracing for free.

TypeScript Tasks

Cross platform tasks are written in TypeScript. It is the preferred way to write tasks once.

NPM version VSTS

Documentation: Creating Node Tasks with the Typescript API

PowerShell Tasks

A task which automates Powershell technologies can be written with our Powershell SDK. These only run on Windows.

Documentation: PowerShell API

Notes on authoring Tasks

Starting from version v2.141.0, the agent can now run on three OS architectures: x86, x64, and 32-bit ARM. When authoring a new task, you can check agent variable: Agent.OSArchitecture (possible values: X86, X64, ARM) to restrict running said task to a particular set of OS architectures.

Security issues

Do you think there might be a security issue? Have you been phished or identified a security vulnerability? Please don't report it here - let us know by sending an email to [email protected].

azure-pipelines-task-lib's People

Contributors

aarnott avatar alex-peck avatar andreyivanov42 avatar annaopareva avatar ashwinichalla avatar brcrista avatar bryanmacfarlane avatar denisnikulin5 avatar denisrumyantsev avatar dmitriibobreshev avatar egor-bryzgalov avatar ericsciple avatar ezzhevnikita avatar hashtagchris avatar ismayilov-ismayil avatar jessehouwing avatar jtpetty avatar keithrob avatar kirill-ivlev avatar konstantintyukalov avatar madhurig avatar max-zaytsev avatar mmajcica avatar roman-shchukin avatar samplegithubaccount avatar stephenmichaelf avatar teh13th avatar tingluohuang avatar tspascoal avatar vtbassmatt avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

azure-pipelines-task-lib's Issues

Add helper to vsts-task-lib to access the WebApi from vsts-agent in a build task

As the title says, it would be very helpful to have helper functions in the vsts-task-lib or vsts-agent to call WebApi functions without having to authenticate (since the agent is already authenticated).

This would prevent us from hard coding credentials in the code or in the build definitions.
It also would fix the issue with typescript build tasks requiring to have basic auth in order to authenticate with the web API (which I currently circumvent by using httpntlm).

This issue is a copy of that issue.

Thanks!

tl.exec on ubuntu automation agent not showing child process out

Invoking child as:
var cmdArgs = "-jar vmOpsTool-1.0.jar" + cmdArgsForAction + commonArgs;
util.log("Invoking command to perform vm operations ...\n");
return tl.exec("java", cmdArgs, {failOnStdErr: true})
.then((code) => {
tl.debug("Exit code: " + code);
tl.exit(code);
})
.fail( (err) => {
tl.error("Failure reason : " + err);
tl.exit(1);
});

Child writes output as:
System.out.println("Parsing input parameters...");

using PowerShell3 execution causes "Cannot process command because of one or more missing mandatory parameters"

Hi,

I have a task using the following input...

 "inputs": [
     {
      "name": "NuGetServerEndpoint",
      "type": "connectedService:Generic",
      "label": "NuGet Server Endpoint",
      "required": true,
      "helpMarkDown": "The NuGet server generic endpoint."
    }
  ],

and in my PowerShell script have the corresponding Params

Param
(
    [Parameter(Mandatory=$true)]
    [string]$NuGetServerEndpoint
)

If i use "PowerShell" the task runs fine - however when i use "PowerShell3" i get the error as per the subject "Cannot process command because of one or more missing mandatory parameters"

Do i need a different type when using Powershell3? I have installed the ps module as per the documentation and when running locally "Invoke-VstsTaskScript -ScriptBlock { . .\MyTask.ps1 }" all works fine (except im asked for the parameter $NuGetServerEndpoint) despite the fact i declare it as...

$env:INPUT_NuGetServerEndpoint = "EP1"
$env:ENDPOINT_URL_EP1 = 'http://nuget.org'
$env:ENDPOINT_AUTH_EP1 = '{ "Parameters": { "UserName": "Some user", "Password": "Some password" }, "Scheme": "Some scheme" }'
$env:ENDPOINT_DATA_EP1 = '{ "Key1": "Value1", "Key2": "Value2" }'

Can you please provide some help on this?

Much appreciated
ExampleFiles.zip.zip

Generated npm package has ///<reference> to non-existent files, causing build breaks

For instance, lib/toolrunner.js and d.ts/vso-task-lib.d.ts both have the following at the top of the file.

/// <reference path="../definitions/node.d.ts" />
/// <reference path="../definitions/Q.d.ts" />

Then, when I try to build a custom task using TypeScript that references this npm package, I get compile errors.

src\Tasks\MyCustomTask\node_modules\vso-task-lib\d.ts\vso-task-lib.d.ts(1,1): error TS6053: File 'd:/git/src/Tasks/MyCustomTask/node_modules/vso-task-lib/definitions/node.d.ts' not found.
src\Tasks\MyCustomTask\node_modules\vso-task-lib\d.ts\vso-task-lib.d.ts(2,1): error TS6053: File 'd:/git/src/Tasks/MyCustomTask/node_modules/vso-task-lib/definitions/Q.d.ts' not found.

I should be able to install the npm package and build against it successfully.

Accessing secret variables from release task

Hello,

We have built a VSTS extension that adds UI to the work item dialog, and a task to update some state in our application.

The rollout task reads a few inputs like release.releaseId and System.TeamProjectId. It also expects the user to set some variables so that the task can make authenticated calls to VSTS. One such call fetches the work items associated with a release via the Release API.

The authentication currently only works with alternate credentials or PAT. So the user needs to set username and password variables on the release. The task then reads them via getVariable. The code looks something like this:

var https = require('https');
var tl = require('vso-task-lib/vsotask');
var username = tl.getVariable('username', false);
var password = tl.getVariable('password', false);
var auth = username + ':' + password;

https.request({..., auth: auth}, function(res) {
  ...
});

The issue we're running into is that the password variable is undefined if it is made secret in the UI, and authenticated VSTS calls fail.

Is there a separate method we can use to read secret variables?

Best,

Alexis

.d.ts file being generated with the wrong module names

The vso-task-lib.d.ts file is being generated with

declare module 'vso-task-lib/taskcommand' {
    ...
}

but the folder structure of the npm module is acutally vso-task-lib/lib/taskcommand.js. This means the generated .d.ts file should contain

declare module 'vso-task-lib/lib/taskcommand' {
    ...
}

in order for the module to be loaded by NodeJS via require('vso-task-lib/lib/taskcommand'). I think this should be a small fix to the gulpfile as part of the configuration of the dts generator.

tl.exit does not exit

Here's the code, it doesn't actually exit:

// back compat: should use setResult
function exit(code) {
    var result = code == 0 ? 'Succeeded' : 'Failed';
    debug('task result: ' + result);
    command('task.complete', { 'result': result }, 'return code: ' + code);
}

Debugging Task Tests

I'm trying to debug my unit tests for a task I'm writing. I'm working with VS Code and I can get the test to run but never hit any debug points. Is there a recommended configuration for doing this?

VSTest task fix for dll search seems to be missing from on premise Team Foundation 2015 Update 3

I have an on premise instance of Team Foundation 2015 Update 3 but I am missing this fix from Feb 2016:

microsoft/azure-pipelines-tasks@fe09697

The version of the VSTest task is 1.0.32 and looking in VSTest.ps1 in the folder \agent\tasks\VSTest\1.0.32\ I have this:

# check for solution pattern
if ($testAssembly.Contains("*") -Or $testAssembly.Contains("?"))
{
    Write-Verbose "Pattern found in solution parameter. Calling Find-Files."
    Write-Verbose "Calling Find-Files with pattern: $testAssembly"    
    $testAssemblyFiles = Find-Files -SearchPattern $testAssembly -RootFolder $sourcesDirectory
    Write-Verbose "Found files: $testAssemblyFiles"
}
else
{
    Write-Verbose "No Pattern found in solution parameter."
    $testAssemblyFiles = ,$testAssembly
}

I would be expecting this:

$testAssemblyFiles = @()
# check for solution pattern
if ($testAssembly.Contains("*") -Or $testAssembly.Contains("?"))
{
    Write-Verbose "Pattern found in solution parameter. Calling Find-Files."
    Write-Verbose "Calling Find-Files with pattern: $testAssembly"    
    $testAssemblyFiles = Find-Files -SearchPattern $testAssembly -RootFolder $sourcesDirectory
    Write-Verbose "Found files: $testAssemblyFiles"
}
else
{
    Write-Verbose "No Pattern found in solution parameter."
    $testAssemblyFiles += ,$testAssembly.Split(";")
}

This is my version of TFS

image

Looking at the release of Update 3, it looks like this fix should be included:

https://www.visualstudio.com/en-us/news/releasenotes/tfs2015-update3-vs#testing

There doesn't seem to be any way of updating the task other than doing it manually which doesn't seem like the right thing to do.

Please support `tl.GetVariables`

it's easy to access a single variable, but accessing lists(of) variables and doing matching against variable names is hard. I could query the environment, but then it's hard to distinguish between values stored in the environment and which ones have been added through the build system.

A simple comma delimited list of variables would be welcome. It could simply be one more environment variable which is set when the task is initialized.

Updating task lib through vsoagent-installer

I feel like this is something I'm doing wrong but I can't quite figure this out, apologies. I have updated the vsoagent-installer:

sudo npm install vsoagent-installer -g

and the output indicates [email protected]

I then execute vsoagent-installer on my agent which pulls in the new scripts. For vso-task-lib the package.json indicates a version of 0.4.5 but the related change to lib/vsotask.js isn't there. This is consistent with what I'm seeing in /usr/local/lib/node_modules/vsoagent-installer/node_modules/vso-task-lib.

It's weird I'm seeing the 0.4.5 version but not an updated vsotask file, am I missing a step? Thanks in advance.

Get-VstsEndpoint for Azure RM Endpoint missing subscription info

The subscription name/id is missing for an Azure RM Endpoint, looks like it should be $Endpoint.Data.SubscriptionId based on this task?

code in custom task

$ConnectedService = Get-VstsInput -Name ConnectedService -Require
$Endpoint = Get-VstsEndpoint -Name $ConnectedService -Require
"Endpoint:"
$Endpoint | ConvertTo-Json -Depth 32

output

Endpoint:
{
    "Auth":  {
                 "parameters":  {
                                    "serviceprincipalid":  ********,
                                    "serviceprincipalkey":  ********,
                                    "tenantid":  ********
                                },
                 "scheme":  "ServicePrincipal"
             },
    "Url":  "https://management.core.windows.net/"
}

minimatch should be runtime dependency

minmatch module is currently set as dev dependency but it's used inside the task lib code. the require need to be removed or the module should be referenced in the dependency section.

Cannot find module "..."

Hello,

I was testing my node task to make sure it worked on the hosted agents, and was getting a "Cannot find module 'vso-task-lib'". I was using relative paths (var tl = require('../../../../node_modules/vso-task-lib'); ) and that worked on my local agent, but not on the hosted one.

I have 2 questions:

  1. I found an article that recommended that the task lib be installed in the task folder; so the task folder now has a node_modules directory with the library and anything that the task requires. Is this the way to go?
  2. Was vso-task-lib renamed to vsts-task-lib?

Thanks!

Alexis

toolrunner failing in Win7 with ENOENT when running a command globally installed with npm-g

I am experiencing an issue which I think it is related with this node issue 2318

I have a build definition with one step only with the task Npm and configured to do do just npm --version. When I run a build in my Win7 I'm getting an error

return code: 1

After some debugging, here is the error that is being bubbled in the promise rejected by the toolrunner

C:\Users\bfcamara\AppData\Roaming\npm\npm failed. spawn C:\Users\bfcamara\AppData\Roaming\npm\npm ENOENT

Here is what I see in the VSTS console

******************************************************************************
Starting task: npm install
******************************************************************************
Set workingFolder to default: E:\Temp\VsoAgent\tasks\Npm\0.2.0
C:\Users\bfcamara\AppData\Roaming\npm\npm install --version
Promise rejected with Error: C:\Users\bfcamara\AppData\Roaming\npm\npm failed. spawn C:\Users\bfcamara\AppData\Roaming\npm\npm ENOENT
return code: 1
******************************************************************************
Finishing task: Npm
******************************************************************************

I'm getting this error in any build task that are wrappers for node commands installed globally. From what I could investigate the tl.which("npm") is returning the full path without the extension .cmd. Then it seems there is a known issue in child_process.spawn on windows that it doesn't look for the path with known executable extensions (.cmd, .bat, etc.)

I found this issue while I was doing some tests with a custom build task that is a wrapper for '''tfx extension''' command,

Debug method being called from getInput in Task.ts in vsts-task-lib

I am taking an inline script as an input in AzureCLI Task, and the inline script is being shown in the console, which is not required.
The method "getInput" in task.ts in vsts-task-lib calls the function "debug" which calls further more function and the input line is printed to the console after string.trim done in "getInput" method. Because of this, inline script input is shown in the console ( the first line of the script is never printed).
thus it happens when the inline script is greater than one line.

do we really need to print the values we get through getInput ??? can we avoid printing the input values to the console ?

Use powershell commands in script task

Hello, sorry for the perhaps noobish question but is it possible to use the powershell sdk commands inside a regular script task and not write a complete custom task?

What I want to do in the end is loop though a parameters.xml file and look up the parameters in there against the running release definition. I've seen that this can be done with environment variables, but that does not include secret variables, something that i'd need for my scenario.

Perhaps there is a different way to do this than using the sdk?

Error: Cannot find module 'vsts-task-lib'

Hey guys.
Everything worked fine untill today. And now when i add Cordova Command to my build steps i get
Set workingFolder to default: D:\agent\tasks\CordovaCommand\1.2.0

module.js:338
throw err;
Error: Cannot find module 'vsts-task-lib'
at Function.Module._resolveFilename (module.js:336:15)
at Function.Module._load (module.js:278:25)
at Module.require (module.js:365:17)
at require (module.js:384:17)

at Object. (D:\agent\tasks\CordovaCommand\1.2.0\lib\vsts-task-lib-proxy.js:35:7)
at Module._compile (module.js:460:26)
at Object.Module._extensions..js (module.js:478:10)
at Module.load (module.js:355:32)
at Function.Module._load (module.js:310:12)
at Module.require (module.js:365:17)

any ideas or hint where should i look at?

Localization tl.loc does not have access to field names

Given this field def
{
"name": "uploadProxyUser",
"type": "string",
"label": "Proxy Username",
"defaultValue": "",
"required": false,
"helpMarkDown": "" ,
"groupName":"scan"
}

I see that "loc.input.label.uploadProxyUser": "Proxy Username", is in the resource file.

but tl.loc("loc.input.label.uploadProxyUser") gets "Can't find loc string for key: loc.input.label.uploadProxyUser"

What's the proper way to handle localization of field name and be able to refer back to it for validation error messages.

ToolRunner.exec does not work on Windows when both toolPath and arguments contain spaces

Use case and traces: microsoft/azure-pipelines-tasks#2253

It looks like this is caused by nodejs/node#7367.

Manually patching the build agent fixes this (javascript resulting from https://github.com/Microsoft/vsts-task-lib/blob/master/node/toolrunner.ts#L232, slightly rewritten to remove typescript-specific syntax):

var isWindowsShellScript = this.toolPath.endsWith('.cmd') || this.toolPath.endsWith('.bat');
var toolPath = this.toolPath.indexOf(' ') === -1 ? this.toolPath : '"' + this.toolPath + '"';
var args = this.args.map((arg: string) => arg.indexOf(' ') === -1 ? arg : '"' + arg + '"');
var cp = child.spawn(toolPath, args, { cwd: ops.cwd, env: ops.env, shell: isWindowsShellScript });

(clearly wrapping args in double quotes is a hack, this is just to prove the point - without that Gulpfile.js still is not found).

Get-VstsEndpoint returning masked credentials

I'm not sure if this intended behavior, but I need to be able to read the credentials from the endpoint information and have had little luck doing so.

I'm making the following call (I've attempted w/ and w/o -Require)
$endpoint = Get-VstsEndpoint $ConnectedServiceName

and when serializing to JSON, it yields:

auth: {"parameters":{"username":"********","password":"********"},"scheme":"UsernamePassword"}

and both the username and password properties are reporting as System.String.

I was initially using this with a custom service endpoint and auth scheme, removed those out of the equation and went to Generic, still the same behavior.

Is this expected or is there a way to correct this? I'm assuming there is given that I've seen examples of people making the call, presumably successfully.

VSBuild and PublishSymbols fail after upgrade to TFS 2015 Update 2 RTM in Japanese locale.

CI build failed in my environment after I upgrade TFS 2015 Update 1 to TFS 2015 Update 2.

logs:
2016-04-02T21:41:21.6214276Z C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -NoLogo -Sta -NoProfile -NonInteractive -ExecutionPolicy Unrestricted -Command ". ([scriptblock]::Create('if (!$PSHOME) { $null = Get-Item -LiteralPath ''variable:PSHOME'' } else { Import-Module -Name ([System.IO.Path]::Combine($PSHOME, ''Modules\Microsoft.PowerShell.Management\Microsoft.PowerShell.Management.psd1'')) ; Import-Module -Name ([System.IO.Path]::Combine($PSHOME, ''Modules\Microsoft.PowerShell.Utility\Microsoft.PowerShell.Utility.psd1'')) }')) 2>&1 | ForEach-Object { Write-Verbose $_.Exception.Message -Verbose } ; $env:TF_BUILD = 'True' ; Import-Module -Name 'C:\agent\tasks\VSBuild\1.0.24\ps_modules\VstsTaskSdk\VstsTaskSdk.psd1' -ArgumentList @{ NonInteractive = $true } -ErrorAction Stop ; $VerbosePreference = 'SilentlyContinue' ; $DebugPreference = 'SilentlyContinue' ; Invoke-VstsTaskScript -ScriptBlock ([scriptblock]::Create('. ''C:\agent\tasks\VSBuild\1.0.24\VSBuild.ps1'''))"
2016-04-02T21:41:29.5855730Z ##[error]':' または '}' ではなく無効なオブジェクトが渡されました。 (473): {
2016-04-02T21:41:29.5855730Z ##[error] "loc.messages.PSLIB_ContainerPathNotFound0": "繧ウ繝ウ繝・リ繝シ縺ョ繝代せ縺瑚ヲ九▽縺九j縺セ縺帙s: '{0}'",
...
2016-04-02T21:41:29.6793302Z ##[error] "loc.messages.PSLIB_TaskVariable0": "'{0}' 繧ソ繧ケ繧ッ螟画焚"
2016-04-02T21:41:29.6793302Z ##[error]}

troubleshooting:
The log provided above seems incorrect encoding.
I tried to build ASP.NET and Console App provided default by visual studio and both failed.
TFS App server and Build Agent server are separately installed on 2 hosts.

Versions:
Windows Server 2012 R2 (Locale=ja_jp)
TFS 2015 Update 2 (C:/agent/tasks/VSBuild/1.0.24)
Visual Studio 2015 Update 2

tl.exec not showing error message in child process as errors

Using tl.exec method to invoke a jar which in turn performs some operations and logs errors in failure cases. tl.exec method is logging all the messages to output stream even though child is writing error stream.

Java script calls jar the following way:
var cmdArgs = "-jar vmOpsTool-1.0.jar" + cmdArgsForAction + commonArgs;
util.log("Invoking command to perform vm operations ...\n");
return tl.exec("java", cmdArgs, {failOnStdErr: true})
.then((code) => {
tl.debug("Exit code: " + code);
tl.exit(code);
})
.fail( (err) => {
tl.error("Failure reason : " + err);
tl.exit(1);
});

Child writes the following way:
System.err.println(exp.getMessage() != null ? exp.getMessage() : "Unknown error occured");.

Sample requested: How to parse the output from a tool as XML or JSON

currently using:

const result = tfx.execSync(<any>{ silent: true });
tl.exitOnCodeIf(result.code, result.code != 0);

const json = JSON.parse(result.stdout)

This gives me access to the stdout (and ignores silent:true for some reason), but I'd like to pass it a string or stream or something to capture the output and allow me to parse it while piping it.

Something like:

// NOT WORKING
let out = ?;
const result = tfx.exec(<any>{ silent: true, stdout=out }).Then
( code => {
    const json = JSON.parse(out)
}

An example of such functionality would be nice :).

Packaging this lib causes tfx-cli to fail when running `extension create`

Since vsts-task-lib contains some files that aren't acceptable to the file --mime-type command, packaging fails.

In order to bypass this error, it requires 2 environment variables to be set:

export LC_CTYPE=C 
export LANG=C

This allows the tfx extension create --manifest-globs vss-extension.json command to run w/ out error.

  • the error is shown below:

image

The "root" of the error is in the file --mime-type - which when run emits the following:

resources.resjson: ERROR: line 22: regexec error 17, (illegal byte sequence)

Setting the 2 env variables on OS X (latest) 10.11.4 and prior versions - packages the file OK.

Unable to assert within TaskMockRunner

I have a task does a regex replace based on tokens in a file (getting values from the variables in the build). To test, I’ve pulled in mock-fs to fake a file. The problem is that I can’t see a way to validate that the replacement actually happened, either in the test or after the test.

I’ve got a _testSuite file that creates a MockTestRunner to run a test, defined in test-atTokens.ts. This file in turn creates a mock TaskMockRunner – this is where I create a mock-fs instance to fake the file system (which I register with the TaskMockRunner).

Now after the task completes in the test run, I want to validate the replacement. I tried adding asserts to the test-atTokens file, but even though they fail the test still passes. In theory I could check the results in the _testSuite file, but I can’t see how to get a reference the mock-fs instance. So I’m stuck – I can’t see a way to assert from within the TaskMockRunner!

Is there a better way to test this or are there some methods missing in the mock classes for testing tasks?

tl.which finds shell script before `.cmd`

When trying to find an executable on Windows, tl.which will find the extensionless shellscript version before finding the matching .cmd. When calling into Node this requires us to always add:

if (tl.osType == "Windows_NT")
{
        tool += ".cmd";
}

which is pretty useless... extensionless files can't be executed by default... Windows always searches in a fixed order. Is there any way to have tl.which prefer tool.cmd over tool.?

Wouldn't it make sense if it would respect the pathext variable?

C:\>echo %pathext%
.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC

Retrieve an input with unexpanded variables

I wonder if there is an undocumented way to retrieve a task input without variable being expanded.

The use case is that I have a JSON input. Users might use variable to adjust that json values, but variable must be escaped during replacement. (more details here)

There are several ways to perform this :

  • Performing the replacement myself but I need a way to retrieve raw input
  • Adding a custom syntax (such as #(VariableName)) to my task (not a big fan of this approach)
  • Having a way to provide custom formatting filters to VSTS such as $(VariableName:formatter(args)) or $(VariableName | formatter:args) and in that case I would provide a jsonEscape filter.$(VariableName:jsonEscape)

Let me know what you think.
Regards

Exec ToolRunner against remote servers

I was wondering if it is possible to provide a ToolRunner with remote machine information so that exec runs the tool on remote machines. It looks like this functionality exists for PowerShell tasks via Invoke-RemoteDeployment which is part of the module Microsoft.TeamFoundation.DistributedTask.Task.Deployment.RemoteDeployment.

If this hasn't been implemented yet, I would propose that an option remote be added to IExecOptions with the following syntax:

/**
 * Interface for exec remote options
 */
export interface IExecRemoteOptions {
    /**
     * List of machines to execute the command on. Can be IP Address, FQDN, or Machine Group Name
     * @type {string[]}
     */
    machines: string[];
    /**
     * Optional: The username to use when executing the command
     * @type {string}
     */
    username?: string;
    /**
     * Optional: The password to use when executing the command
     * @type {string}
     */
    password?: string;
    /**
     * Optional: Must be 'http' or 'https'
     * Default: https
     * @type {string}
     */
    protocol?: 'http' | 'https';
    /**
     * Optional: Whether or not the tools should run in parallel on the remote machines
     * Default: false
     * @type {boolean}
     */
    parallel?: boolean;
}

And its usage would be:

var tool = createToolRunner("foo.exe");
tool.exec({
    remote: {
        machines: ['127.0.0.1', 'server.remote.com', 'my-machine-group']
        username: 'username'
        password: 'password',
        protocol: 'https',
        parallel: true
    }
});

On Windows machines this could use WinRM similar to the Invoke-RemoteDeployment command. On Linux and Mac's it could use SSH. This would allow for tasks written in node to be able to target remote machines.
http://vsts-deploy-guide.readthedocs.org/en/latest/target-machines/

WinRM for Node:
https://www.npmjs.com/package/winrmjs

SSH for Node:
https://www.npmjs.com/package/node-ssh

Object reference not set to an instance of an object

Exact Repro Unknown: the bug occurs when using the ExtractFiles Task from vsts-tasks, cfr.
https://github.com/Microsoft/vsts-tasks/blob/master/Tasks/ExtractFiles/extractfilestask.ts#L225

LOG:

2016-07-04T20:41:40.8832784Z Extracting file: C:\vsobuild_work\064c96c25\REL.xxxx\STAGING1\xxxx-rlsmgmt-STAGING1-20160701.4.zip
2016-07-04T20:41:40.8832784Z [command]7zip/7z.exe x -oc:\deploy\xxxx C:\vsobuild_work\064c96c25\REL.xxxx\STAGING1\xxxx-rlsmgmt-STAGING1-20160701.4.zip
2016-07-04T20:41:40.8872795Z ##[error]Unhandled: Cannot read property 'toString' of null
2016-07-04T20:41:40.8882796Z ##[section]Finishing: Extract files

Debugged it and traced the execution until line https://github.com/Microsoft/vsts-task-lib/blob/master/node/lib/toolrunner.ts#L366
which outputs into our log.

Problem seems to bee some weird condition causes the 7zip process not to have an stdout or stderr pipe at the .toString() lines, 379 & 380

        res.stdout = r.stdout.toString();
        res.stderr = r.stderr.toString();

Can not import powershell module

I have a installation of TFS2015 Update 3 on premise.
I have a agent installed on another machine in version 1.95.3.

I write a simple powershell task that work. I need to improve it.
If in the powershell script I add the line
Import-Module "Microsoft.TeamFoundation.DistributedTask.Task.Internal"
then my build fails with the message :
The specified module 'Microsoft.TeamFoundation.DistributedTask.Task.Internal' was not loaded because no valid module file was found in any module directory.

In my task I embed the SDK in the sub directory ps_modules\VstsTaskSdk.

I do not understand why it fails. Some standard tasks have this instruction and they work correctly.

Support complex input types

Hi,

Currently those functions only support normal variables getting their value through environment variable. It would be great that they also support secret variables like Get-TaskVariable in Microsoft.TeamFoundation.DistributedTask.Task.Internal.

Thanks

Unable to load vsts-task-lib on TFS2015 Update 2 build agent

Hi,

I'm trying to run an extension in Typescript and it fails with the following error:

##[debug]load strings from: C:\TFS2015\tasks\BuildNumberGenerator\1.0.19\node_modules\vsts-task-lib\lib.json

##[debug]load loc strings from: C:\TFS2015\tasks\BuildNumberGenerator\1.0.19\node_modules\vsts-task-lib\Strings\resources.resjson\en-US\resources.resjson

Unhandled: Cannot read property 'match' of undefined

##[debug]task result: Failed

The task is packaged with the node_modules folder in its root containing vsts-task-lib, so I'm not sure what's happening there.

Here are the imports in the code:

var tl = require('vsts-task-lib/task');
var webapim = require('vso-node-api/WebApi');

Also, is there a way to tell the agent to prefer the powershell version over the node version? It seems to always take the node version when it's available.

Thanks!

Hard to intercept output when redirecting StdErr

I tried to execute an executable (tfx) and in case of an error capture the error message. This turns out to be very difficult.

let tr = new tr.ToolRunner(tl.which("tfx.cmd"));
tr.exec(<any>{ failOnStdErr: false, errStream: myStream });

Doesn't redirect anything to myStream, it turns out thet when failOnStderr is false output is instead redirected to StdOut.

But when I capture stdOut, the error message isn't added to my buffer:

let tr = new tr.ToolRunner(tl.which("tfx.cmd"));
tr.exec(<any>{ failOnStdErr: false, outStream: myStream });

Turns out this may have to do with the fact that I did't set IgnoreResultCode: false, because if that's set, it will fail the task before actually allowing me to inspect the result.

I looked at the ANT task and stole

https://github.com/Microsoft/vsts-tasks/blob/master/Tasks/ANT/anttask.ts#L241-L253

But that doesn't seem to work, it doesn't ever receive a line.

I simplified the code and removed the buffer (I get why it's there, but it isn't working it seems) and ended up with:

var buffer;
    tfx.on('stderr', function (data) {
        if (data) {
            var line =  data.toString();
            if (line.indexOf("Error:") >= 0) {
                var tferrorIndex = line.indexOf("TF1590010");
                if (tferrorIndex < 0) {
                    tl.setResult(tl.TaskResult.Failed, line);
                }
                else {
                    console.log(line.substring(tferrorIndex + 11));
                }
            }
        }
    });
    var result = tfx.exec({ silent: true, failOnStdErr: false });

and after a lot of frustration I finally found a way to (so far) reliably intercept the error output and override it.

All in all it took way too much time and I encountered too many surprises.

My expectations would have been:

  • If I supply a error stream, it is called regardless of silent:true and failOnstdErr:false
  • If I set failOnStdErr:true, I expect the task to fail, but still allow me to intercept the output
  • If stdErr is redirected to stdOut by your code, I expect the output to end up in the supplied outStream, right now it bypasses the supplied outStream and is logged to the console.

What is the correct way to debug your scripts in PowerShellOnTargetMachines?

I have a series of Powershell modules that I am executing with PowerShellOnTargetMachines.

I am trying to see the debug statements within the VSTS build log, but I am having a real hard time getting them to come through.

I understand that Write-Host is not recommended for automation, so my question is, what should I use? I have tried Write-Debug, Write-Verbose and made sure the preferences are set right. But when I call a function from the main script all my logging disappears. The only output I can get to appear is Write-Output from the top most script. I obviously can't use Write-Output from called functions as they may return a value.

This is possibly a more generic powershell question, but I am wondering if there are any best practices for use with this task?

How to log "Succeeded With Issues" from TypeScript

In the Powershell SDK there is an option to set the result to SucceededWithIssues. I can't find an equivalent option for the Typescript SDK nor can I find documentation whether logging a warning will have this result.

tl.which on Windows should attempt to find the files in this order .exe .bat .cmd

Apache ANT task has 3 scripts to run ANT: ant.bat for Windows, ant shell script for nix, and ant.cmd for OS/2 apparently. Unfortunately, the ant.cmd is in a format that Windows cannot run (it has a / */ style comment at the top). And this is exactly the one that gets picked by tl.which on Windows. Changing the order to check for .bat first should fix the problem.

mergeResults for CodeCoveragePublisher.publish

Is it possible to provide a mergeResults option for CodeCoveragePublisher.publish (similar the TestPublisher.publish)?

Use Case

I have a simple Web Application using Asp.Net Core & React

I am using xUnit, OpenCover & OpenCoverToCoberturaConverter to produce a Cobertura coverage report for the Asp.Net code.

I am using Jest to produce a Cobertura coverage report for React.

I can publish both (using separate build steps) to VSTS, but the Code Coverage widget are only based on one of the reports.

I would like VSTS to display Code Coverage for the combined results

Get-VstsVssCredentials fails reporting Required: 'SystemVssConnection' service endpoint URL

Hi

I am using v0.7.1 of the vststasksdk PowerShell module in an on-prem TFS 2015 Update 2 installation. The Get-VstsVssCredentials cmdlet is failing reporting

Required: 'SystemVssConnection' service endpoint URL

From looking at the code it appears the module is expecting ENDPOINT_* environment variables to be set but they aren't. Is this expected to work with the on-prem version of TFS or is this module incompatible with update 2?

Thanks

Can this lib be used on TFS 2015 on-prem ?

I have just tried to upload a new version of the Xcode task available here : https://github.com/Microsoft/vso-agent-tasks/tree/master/Tasks/Xcode and I am getting the following error during builds :

module.js:341
throw err;
^
Error: Cannot find module 'vsts-task-lib'
at Function.Module._resolveFilename (module.js:339:15)
at Function.Module._load (module.js:290:25)
at Module.require (module.js:367:17)
at require (internal/module.js:16:19)

So I guess that the TFS 2015 Update 1 that we are using is probably missing that library. How can I install (update?) it on our TFS server ?
I also noticed that the reference to this library in the vso-agent-tasks repo is not in the package.json but in an externals.json, is there a reason for that ?

I am wondering if all these tasks are only for VSO or if the intended use was VSO or TFS on-prem ?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.