Is it possible to substring value in NodeFilter CommandLine Argument in rundeck - rundeck

I have a Rundeck job where I'm loading the env Option values from remote file.
File has values as shown below
domain-dev
In NodeFilter CommandLine Argument, I'm loading values as environment: ${option.env}
I want to do substring of the values of env till -. Eg: I want to give domain to NodeFilter
is it possible to do something like below
NodeFilter = environment: ${option.env.substring(0, option.env.indexOf("-"))}

Is not possible in that way, but you can use regular expressions. To get values from a specific string. For domain-dev you can use this regex name: ^([^-]*).*$ to get only the string before the - character, of course, this example uses the tags attribute to apply the filter.
You can use regex101 or freeformater to test your regex patterns.

Related

match string pattern by certain characters but exclude combinations of those characters

I have the following sample string:
'-Dparam="x" -f hello-world.txt bye1.txt foo_bar.txt -Dparam2="y"'
I am trying to use RegEx (PowerShell, .NET flavor) to extract the filenames hello-world.txt, bye1.txt, and foo_bar.txt.
The real use case could have any number of -D parameters, and the -f <filenames> argument could appear in any position between these other parameters. I can't easily use something like split to extract it as the delimiter positioning could change, so I thought RegEx might be a good proposition here.
My attempt is something like this in PowerShell (can be opened on any Windows system and copy pasted into it):
'-Dparam="x" -f hello-world.txt bye1.txt foo_bar.txt -Dparam2="y"' -replace '^.* -f ([a-zA-Z0-9_.\s-]+).*$','$1'
Desired output:
hello-world.txt bye1.txt foo_bar.txt
My problem is that I either only take hello-world.txt, or I get hello-world.txt all the way to the end of the string or next = symbol (as in the example above).
I am having trouble expressing that \s is allowed, since I need to capture multiple space-delimited filenames, but that the combination of \s-[a-zA-Z] is not allowed, as that indicates the start of the next argument.

Azure Devops: Shorten $(SourceBranchName) when used within pipeline name directive

Our yml-definition files for an Azure-pipeline start with
name: $(Build.DefinitionName)_$(SourceBranchName)_$(rev:rrrrr)
With that, we get very long build names that have negative consequences for display in build result pages. Therefore we would like to shorten the $(SourceBranchName) to the e.g. first 20 characters.
Is there a way of doing that?
we would like to shorten the $(SourceBranchName) to the e.g. first 20 characters.
You could try to use command line\powershell script to split long string into short.
steps:
- script: |
echo $(Build.SourceBranchName)
set TestVar=$(Build.SourceBranchName)
set MyCustomVar= %TestVar:~0,20%
echo %MyCustomVar%
echo ##vso[task.setvariable variable=CustomVar]%MyCustomVar%
displayName: 'Get the first 20 character versions of Build.SourceBranchName'
Then we could get the short string of the SourceBranchName.
Generally, SourceBranchName is different from SourceVersion, and it is generally not a very long string. If your SourceBranchName is indeed a very long string, then the above method will help you.
You could check my previous thread for some more details.
Note: If you want to shorten your build names, we need update the build number for current build through Logging Command (e.g. Write-Host "##vso[build.updatebuildnumber]buildnumber"):
Write-Host "##vso[build.updatebuildnumber]$(Build.DefinitionName).$(CustomVar).$(rev:rrrrr)"
But the $(rev:rrrrr) could not be available in the task, so we have to include $(rev:rrrrr) in default build number format (Options), for example: $(date:yyyyMMdd)-$(rev:rrrrr). And Get current build number from pre-defined variable (Build.BuildNumber/BUILD_BUILDNUMBER), then we parse the value of $(rev:rrrrr).

Azure DevOps variable and multiline value

I have an Azure Devops Pipeline Task for .NET Core, specifying the 'test' command.
One of the parameters is 'Path to project(s)'. You can specify multiple globbing patterns, each on its own line.
Now I want to make this value settable at queueing time by using a variable $(UnitTestPatterns). But a variable cannot have a multiline value. How can I specify 2 or more globbing patterns in a way that all are evaluated?
I have tried a pipe '|', a comma ',' and a semicolon ';' as separators, none have worked. The log of the task then shows ##[warning]Project file(s) matching the specified pattern were not found.
Example multiline value:
**/Project.*.Tests/*.csproj
!**/Project.Module2.Tests/*.csproj
I want a variable like this (with probably some secret separator, the ';' does not work):
$(UnitTestPatterns) = **/Project.*.Tests/*.csproj; !**/Project.Module2.Tests/*.csproj
I am using the UI to set the variable, not YAML.
It looks that this is not supported. Please check this topic on Developer Community. You may also check this topic where you will find workaround.

Why is #regex used in task.json in Azure DevOps extension? What does it check for?

I came across this and was wondering what this means and how it works?
What's the significance of using #regex here and how does it expand?
https://github.com/microsoft/azure-pipelines-tasks/blob/master/Tasks/DownloadPackageV0/task.json
"endpointUrl": "{{endpoint.url}}/{{ **#regex ([a-fA-F0-9\\-]+/)[a-fA-F0-9\\-]+ feed }}_apis**/Packaging/Feeds/{{ **#regex [a-fA-F0-9\\-]*/([a-fA-F0-9\\-]+) feed** }}{{#if view}}#{{{view}}}{{/if}}/Packages?includeUrls=false"
Also I would like to know how many packages will it return and display in the Task input UI dropdown if there are thousands of packages in the feed. Is there a known limit like first 100 or something?
#regex doesn't appear to actually be documented anywhere, but it takes two space-delimited arguments. The first is a regular expression and the second is a "path expression" identifying what value to match against, in this case the value of the feed input parameter. If the regex matches the value, it returns the first capturing subexpression, otherwise it returns the empty string.
In this particular context, the feed parameter is formatted as 'projectId/feedId', where projectId and feedId are GUIDs, and projectId and the / are eliminated for organization-scoped feeds (i.e. feeds that are not inside a project). The first regex therefore extracts the project ID and inserts it into the URL, and the second regex extracts the feed ID and inserts it into the URL.
As of this writing, the default limit on the API it's calling is 1000.
Regex stands for regular expression, which allows you to match any pattern rather than an exact string. You can find more info on how to use it in Azure Devops here
This regex is very specific. In this case, the regex ([a-fA-F0-9\\-]+/)[a-fA-F0-9\\-]+\ matches one or more of the following 1) letters a-f (small or capital) Or 2) \ Or 3) - followed by / and then again one or more of those characters.
You can copy the regex [a-fA-F0-9\\-]+/)[a-fA-F0-9\\-]+ into https://regexr.com/ to play around with it, to see what does and doesn't match the pattern.
Examples:
it matches: a/a a/b abcdef-\/dcba
but doesn't match: /a, abcdef, this-doesn't-match
Note that the full endpoint consists of concatenations of both regular expression and hardcoded strings!

Does intersystems cache have a wildcard to search global node?

Sometimes i want to search a character with wildcard, I don't want to search all the global nodes to find specific characters. so i want to know is any wildcard i can use to match specific characters on global nodes. as if i want to find ^G("abc") in ^G with ^G("*s*")
There is no way to do this using low level $order/$query functions as #
kazamatzuri correctly said, but you can use %Library.Global:Get class query - first parameter is namespace, and second parameter is pattern string. You can have a documentation on pattern syntax in the class itself or here https://docs.intersystems.com/irislatest/csp/docbook/DocBook.UI.Page.cls?KEY=GGBL_managing#GGBL_managing_view
Here is an example using CALL statement - let's assume we want to find all global nodes in ^%SYS global of USER namespace starting with "D":
DEV>d $system.SQL.Shell()
SQL Command Line Shell
----------------------------------------------------
The command prefix is currently set to: <<nothing>>.
Enter <command>, 'q' to quit, '?' for help.
[SQL]DEV>>call %Library.Global_Get('USER','^%SYS("D":"E"')
1. call %Library.Global_Get('USER','^%SYS("D":"E"')
Dumping result #1
Name Value Name Format Value Format Permissions
^%SYS("DBRefByName","CONFIG-ANALYTICS") ^^f:\trakcare\config\db\analytics\ 1
^%SYS("DBRefByName","CONFIG-APPSYS") ^^f:\trakcare\config\db\appsys\ 1 1
^%SYS("DBRefByName","CONFIG-AUDIT0") ^^f:\trakcare\config\db\audit0\ 1 1
^%SYS("DBRefByName","CONFIG-AUDIT1") ^^f:\trakcare\config\db\audit1\ 1 1
^%SYS("DBRefByName","CONFIG-AUDIT2") ^^f:\trakcare\config\db\audit2\ 1 1
No.
You'll have to implement that yourself using $ORDER or $QUERY. There are pattern matching and regex utils though.
Cheers!