Reputation: 1096
I'm currently rewriting a custom TFS Build Task so it is based on Node.js instead of PowerShell. However I ran into the following problem:
In the existing Task, the user can decide if he want's the Task Result written into an environment variable. This is useful if he wants to add some scripts himeself that work with whatever the result of the task is. In PowerShell I achieved that by setting a "User-Level Environment Variable" like this:
[Environment]::SetEnvironmentVariable($variableName, "The Value to Set", "User")
and it could be read out after the task was finished, for example in PowerShell like this:
$variable = [Environment]::GetEnvironmentVariable($variableName,"User")
However I did not find any way to achieve the same thing with the Task in Node.js. If you set it via process.env["variable"]
this not be available in any of the following tasks that are executed.
After some searching I stumbled over the the setTaskVariable method that the VSTS TaskLib offers: https://github.com/Microsoft/vsts-task-lib/blob/master/node/docs/vsts-task-lib.md#tasksetTaskVariable
However now I don't know how to access this variable in a subsequent Task. I see that you can use getTaskVariable if you use a custom Task based on the tasklib (either in PowerShell or Node), but I don't want that everybody that wants to use the variable needs to write a complete task if a simple (PowerShell) Script would do.
So is there an "easy" way to get this TaskVariable for in a script that follows or is it just for "full fletched" tasks? What other options would I have when to simply pass some info to a script that would follow my task?
Upvotes: 0
Views: 745
Reputation: 33698
The simple way is using Task Logging commands: ##vso[task.setvariable]value
(e.g. Console.log(‘##vso[task.setvariable variable=testvar;]testvalue’
), then you can use it as the general variable that defined in the build/release definition. (e.g. a task’s arguments: $(testvar)
)
On the other hand, task.setVariable method can do the same thing. (The task.setTaskVariable is used for current task's subsequent steps)
Upvotes: 2