Home > OS >  Environment variable in jenkins not printing
Environment variable in jenkins not printing

Time:05-12

I am creating an environment variable in my freestyle Jenkins project like this

$files1 =Get-ChildItem $ENV:WORKSPACE/altab
write-output $ENV:WORKSPACE
$linklist = [System.Collections.ArrayList]@()
$prefix="http://x.x.x.x:8080/job/ws/altab/"
foreach ($file in $files1) {
  $url1 = '<a href=' '"' [uri]::EscapeUriString($prefix $file.Name) '">' 'PDF LINK' '</a>'
  $null = $linklist.Add($url1) 
 }
$links = $linklist | Out-String
"LINKS_VAR=$links" | Out-File env.properties -Encoding ASCII

The environment variable looks like this

LINKS_VAR=<a href="http://x.x.x.x:8080/job/ws/altab/EC2AMAZ-MTI08HS_Open Google_20220504-064713.pdf">PDF LINK</a>
<a href="http://x.x.x.x:8080/job/ws/altab/EC2AMAZ-MTI08HS_Open Google_20220504-065759.pdf">PDF LINK</a>
<a href="http://x.x.x.x:8080/job/ws/altab/EC2AMAZ-MTI08HS_Open Google_20220504-070700.pdf">PDF LINK</a>

I am using the email extension plugin in Jenkins to send this environment variable in the email. In the email body I have LINKS_VAR. However, only first URL is being sent in the mail. Where am I going wrong?

CodePudding user response:

Do it like this. Add a <br> tag instead of a new line like you are doing.

$files1 =Get-ChildItem $ENV:WORKSPACE/altab
write-output $ENV:WORKSPACE
$linklist = [System.Collections.ArrayList]@()
$prefix="http://x.x.x.x:8080/job/ws/altab/"
foreach ($file in $files1) {
  $url1 = '<a href=' '"' [uri]::EscapeUriString($prefix $file.Name) '">' 'PDF LINK' '</a>' '<br>'
  $null = $linklist.Add($url1) 
 }

"LINKS_VAR=$linklist" | Out-File env.properties -Encoding ASCII
  • Related