What does this phrase in the jenkinsfile mean? - jenkins-pipeline

What does this phrase in the jenkinsfile mean?
env.ForEmailPlugin = env.WORKSPACE
Where can I find the value of env.WORKSPACE ?

Related

/^a-eg-h/.match('f') gives null in Ruby

The expression /^a-eg-h/.match('f') gives me nil in Ruby interpretor(2.3.1). I'm unable to figure out whats wrong.
Any suggestions ?
Ruby documentations states 'above expression should return #<MatchData "f">'.
As has been mentioned in the comments, your pattern is incorrect. It appears that you're attempting to use a character class, but have neglected to include the surrounding square brackets. Your pattern, as it currently stands, will only match on strings that start with the literal text a-eg-h. The pattern you want is:
/[^a-eg-h]/
Additionally, attempting to match the string j with this pattern will fail and return nil in Ruby, as the string does not match the pattern. A better way to go about this would be something like:
match = /[^a-eg-h]/.match(str)
if (match)
do_something()
end

Regular expression to fetch the value from a given string

I have the following string:
a=<record><FPR_AGENT_CODE>990042833</FPR_AGENT_CODE><FPR_AGENT_LABELCODE>CIF Code :</FPR_AGENT_LABELCODE><FPR_AGENT_LABELNAME>CIF Name :</FPR_AGENT_LABELNAME>
I need to get the value from:
<FPR_AGENT_CODE>990042833</FPR_AGENT_CODE>
to
"FPR_AGENT_CODE 990042833 FPR_AGENT_CODE"
How can I write the regular expression for this? I tried using the one given below, but it's not working.
puts a[/<.*>.*<\/.*>/]
You can use scan with the following regex:
/<([^>]+)>(\d+)<\/\1>/
Sample code:
a="<record><FPR_AGENT_CODE>990042833</FPR_AGENT_CODE><FPR_AGENT_LABELCODE>CIF Code :</FPR_AGENT_LABELCODE><FPR_AGENT_LABELNAME>CIF Name :</FPR_AGENT_LABELNAME><FPR_AGENT_NAME>Mr Kamal Kishore</FPR_AGENT_NAME><FPR_BANK_BRANCH_NAME>STATE BANK OF INDIA KHOUR</FPR_BANK_BRANCH_NAME><FPR_BRANCH_ADDRESS>"
puts a.scan(/<([^>]+)>(\d+)<\/\1>/)
Output:
FPR_AGENT_CODE
990042833
The regex <([^>]+)>(\d+)<\/\1> searches for a string in angle brackets (capturing the text into group 1), then a sequence of 1 or more digits (\d+), and then the closing tag.
If you need to get multiple values, you can use:
puts a.scan(/<([^>]+\b)[^<>]*>(.*?)<\/\1>/)
See another demo, output:
FPR_AGENT_CODE
990042833
FPR_AGENT_LABELCODE
CIF Code :
FPR_AGENT_LABELNAME
CIF Name :
FPR_AGENT_NAME
Mr Kamal Kishore
FPR_BANK_BRANCH_NAME
STATE BANK OF INDIA KHOUR
For multiline input, either use m option, or replace (.*?) with ([^<]*).
puts a.scan(/<([^>]+\b)[^<>]*>(.*?)<\/\1>/m)
Or
puts a.scan(/<([^>]+\b)[^<>]*>([^<]*)<\/\1>/)
See another demo

Regex for extracting text after a specific word between quotes

I have some strings that have a format like this:
"text that comes before\"start\":\"Desired Info\"text that comes after"
I'd like to extract only "Desired Info". It will always be preceded by "\"start\":" and this will only appear once in the string. What regex can I use to do this?
This shall work:
s = "text that comes before\"start\":\"Desired Info\"text that comes after"
s[/(?<="start":")[^"]*(?=")/]
# => "Desired Info"
Here: is the regular expression:
"start":"(.*)"
In code:
match = /"start":(.*)"/.match("text that comes before\"start\":\"Desired Info\"text that comes after");
if match
print match[1]
end
Simplest is:
s[/"start":"(.*?)"/, 1]
#=> "Desired Info"
(?:\\"start\\":\\")(.+)(?:\\")
"Desired Info" into the NON IGNORED capturing group.

ruby regular expression grouping

I am having a problem extracting a substring from a string using regex.
For example I have a string like follows
str = "result[cars][ford]"
Now I need a regex which can extract out cars and ford out of that string so that when
str.match({{regex}})[1]
would provide cars and
str.match({{regex}})[2]
would provide ford
Now i need that regex inside that curly braces.
Any link that helps to this question are most welcomed.
It's actually simple.
s = "result[cars][ford]"
matches = s.scan(/\[(\w+)\]/).flatten # => ["cars", "ford"]
Here's a demo.

Are there any other uses of parenthesis in powershell?

As new to Powershell world, sometime I'm stuck in the tricky syntax. That's why I'm trying to figure out all the possible uses of the parenthesis inside the language.
Do you know some more? Can you add here?
Here mine (left out basic use of curly in pipeline and round in method calls):
# empty array
$myarray = #()
# empty hash
$myhash = #{}
# empty script block
$myscript = {}
# variables with special characters
${very strange variable # stack !! overflow ??}="just an example"
# Single statement expressions
(ls -filter $home\bin\*.ps1).length
# Multi-statement expressions inside strings
"Processes: $($p = “a*”; get-process $p )"
# Multi statement array expression
#( ls c:\; ls d:\)
Cause a statement to yield a result in an expression:
($x=3) + 5 # yields 8
When using generics, you need to wrap the type in [..]:
New-Object Collections.Generic.LinkedList[string]
For some people this might look confusing, because it is similar to indexing in arrays.
The Param( ) statement (in a function, script, or scriptblock)
Around the condition in an If (or Elseif statement)
Around the expression in a switch statement.
Edit: Forgot the condition in the while statement.
Edit2: Also, $() for subexpressions (e.g. in strings).
Regular expressions are arguably a first-class construct in Powershell.
If we're compiling a complete list, we can include the role that square and round brackets play in regular expressions.
An example:
$obj.connectionString = $obj.connectionString -replace '(Data Source)=[^;]+', '$1=serverB\SQL2008_R2'
Because of the support for XML, you can go so far as to include the square brackets used in XPath. (That's really drawing a long bow though :-)
select-xml $config -xpath "./configuration/connectionStrings/add[#name='LocalSqlServer']"
It's even written, but not enough clearly in the first short list after "Multi-statement expressions inside strings I'will add
# Var property inside a string
$a = get-process a*
write-host "Number of process : $a.length" # Get a list of process and then ".length
Number of process : System.Diagnostics.Process (accelerometerST) System.Diagnostics.Process (AEADISRV) System.Diagnostics.Process (agr64svc).length
write-host "Number of process : $($a.length)" # To get correct number of process
Number of process : 3
The parenthesis is most powerfully.
Suppose that you want collect all output, including errors, of some scriptblock and redirect to a variable or another functions for handle this... With the parenthesis, this is easy task:
$customScript = { "This i as test"; This will be procedure error! }
(. $customScript 2>&1 ) | %{"CAPTURING SCRIPT OUTPUT: "+$_}

Resources