VSTS plugin development - Disable parsing env vars in string input - azure-devops

I'm developing an extension to VSTS. The tasks are written in JavaScript.
In the extension, there is a string input field. In this input, the user can enter a path in his file system. The user can use the agent's environment variables, such as ${'Build.SourcesDirectory'}. During the task, I read the input variable by getInput() function of vsts-task-lib/task library.
The problem: I need to get the raw string input in order to process it during the task. For example, instead of c:\agent\_work\1\s i'd prefer to get ${'Build.SourcesDirectory'}.
This is the input field in
task.json:
{
"name": "myName",
"type": "multiLine",
"label": "My Label",
"required": true,
"properties": {
"resizable": "true",
"rows": "10",
"maxLength": "10000"
}
}

The variable value is replaced by the system as soon as the build start. So getInput() method can only get its value rather than the original string. If you do want that strings, call the Rest API to parse the build definition settings.

Related

Enable users of github program to configure their own DCMake prefix path

Consider a situation where people work together on the same code base; c++ with cmake. Code base depends on a library, that must be installed separately.
Each user may have the library in a different location. A user may invoke cmake like this:
cmake -DCMAKE_PREFIX_PATH=/path/for/that/user .
However, this is not very easy in all circumstances (e.g. windows and visual studio), and requires retyping. So instead, we have
list(APPEND CMAKE_PREFIX_PATH "/path/for/user")
In the CMakeLists.txt. This works, but requires people to constantly change that path after pulling a branch, which is annoying and easily forgotten. Is it possible to configure in a way that pulling new branches does not override this path, once set on a specific machine?
You can have each of your users create their own CMakeUserPresets.json file, and set it in the cacheVariables field of a configurePresets entry.
// CmakeUserPresets.json
{
"version": , // pick one
"cmakeMinimumRequired": {
"major": , // pick one
"minor": , // pick one
"patch": // pick one
},
"configurePresets": [
{
"name": "starball",
"displayName": "Starball's config",
"description": "Starball's private configuration preset",
"generator": "...",
"binaryDir": "...",
"cacheVariables": {
"CMAKE_PREFIX_PATH": "..."
},
"environment": {}
}
],
// ...
}
Make sure to put CMakeUserPresets.json in your .gitignore file (or whatever else you have to do for your specific VCS so that the user preset file isn't tracked in the VCS).

Default or prevent ADF Pipeline Activity Parameters

How do you specify that an activity should not be parameterised in an exported ARM template, or ensure the parameter default value is whatever is already specified?
I have an ADF pipeline which contains a WebActivity. This WebActivity URL is set by an expression which concatenates some text with some pipeline parameters:
#concat(pipeline().parameters.URL,'path/',pipeline().parameters.ANOTHER_PARAMETER,'/morePath/', pipeline().parameters.YET_ANOTHER_PARAMETER,'/lastBitOfPath')
When I export the ADF template through the UI, there are some parameters added which look like: PIPELINE_NAME_properties_0_typeProperties, are type String, but are blank. These appear to correspond to the WebActivity URL fields in various activities.
If I then import that ARM template and parameter file into a new Data Factory, the WebActivity URL is blank. This means I need to override the parameter as normal, fine, but why....? I don't need a new parameter to specify a value that is already set by parameters... how do I ensure that this activity is imported with the same expression? It seems mad that to use a WebActivity means you have to parameterise the expression. I want the ARM Template > Export ARM Template to export what I've got, not add redundant parameters that I do not need.
I have also tried editing the pipeline JSON to add a default and defaultValue attribute for the URL activity, but they are removed and have no effect.
It seems the reason for this is that the parameterization template has been modified to include:
"Microsoft.DataFactory/factories/pipelines": {
"properties": {
...
"activities": [{
"typeProperties": {
"url": "-::string"
}
}
]
}
},
Which removes the default for all URL properties of all activities.
https://learn.microsoft.com/en-gb/azure/data-factory/continuous-integration-deployment#use-custom-parameters-with-the-resource-manager-template
This applies to all activites so it seems the only alternative is to specify
"url": "=::string"
Which will parameterise the URL (so any existing parameterization will continue to function) but keep the original value by default. Care must then be taken to override any other activity url properties that I do not wish to move.

Azure devops custom extension output variables

I am trying to create an extension using node api which publishes a path variable on completion.
I did set outputVariables in task.json and tried to use both
tl.setVariable('outVar1', 'outVal1'))
tl.setTaskVariable('outVar1', 'outVal1'))
task.json (only outvariable section):
"OutputVariables": [
{
"name": "outVar1",
"description": "This publish a output variable."
}
],
I tried printing it in the subsequent steps in the same job using all the recomended constructs
$(taskName.outVar1)
$taskName.outVar1
$outVar1
$(outVar1)
But the variable is not visible. I also printed all the environment variables and the variable is not present there.
Is someone able to create an extension which outputs a variable successfully?
You don't need to declare an output variable fro this purpose.
Just set the variable:
tl.setVariable("varNamr","varValue", false);
The fasle indicate that is not a secret variable.
In the enxt steps you can use the variable wirh $(varName).

In VS Code, is there a way to programmatically set the filenamePatterns of a language in package.json

We're able to set context variables in typescript for an extension through the call to vscode.commands.executeCommand('setContext', VarName, VarValue) which are usable in "when" clauses for commands in the package.json. What I'm trying to do is dynamically set the filenamePatterns of a language entry.
"languages": [
{
"id": "MyLanguage",
"aliases": ["MyLanguage", "mylanguage"],
"filenamePatterns": [ /* trying to set this dynamically */ ]
}
Is there a way to do this dynamically, either through setting a context variable or a way to access the language in typescript to set these? I need to pull some values from a config file and create the glob pattern based upon those entries which I don't have ahead of time.

PowerShell parameters for script task

I'm experimenting with PowerShell and having a little trouble understanding parameters.
I added
Param([string]$EmployeZip)
in the .ps1 file.
Also tried
Param([Parameter(Mandatory=$false)] [System.String] $EmployeZip)
And I need to make it as an optional value so the user need not have to enter it.
I am trying to make a VSTS task using this powershell.The issue is, it is looking for the EmployeZip as a mandatory filed, instead of as an optional filed.
How can I make it as an optional filed?
Thanks for the quick responses.
I found it.
inputs": [
{
"name": "EmployeZip",
"type": "string",
"label": "EmployeZip",
"defaultValue": "",
"required": false,
"helpMarkDown": "I"
}
I have to make the "required": false, in the task.json file. it was true.