Get return value from Powershell (Using windows batch command)

985 views
Skip to first unread message

Kake

unread,
Feb 28, 2014, 2:56:38 AM2/28/14
to jenkins...@googlegroups.com
Hi

Using Jenkins to execute some scripts in a continuous integration task.
I have a job who copies some files to a folder, the name of the folder is dynamically created.  I wish to get the name of the folder.. back from my script.

The script is executed using "windows batch command", i.e. 

set scriptpath=%SCRIPT_HOME%\stage.ps1
powershell.exe "& {%scriptpath% -SOURCEFOLDERNAME %SourceFolderName% -SOURCEPATH %SourcePath% -TARGETHOST1 %TargetHost1% -TARGETHOST2 %TargetHost2%; exit $lastexitcode}"
the ps script terminates using  return $stagingFolderName

Have tried to set the dynamic "FolderName"  as a Env variable but it's not accessible after the ps1 is done.. 
#[Environment]::SetEnvironmentVariable("stagingFolderName", $stagingFolderName, "User")
#[Environment]::SetEnvironmentVariable("stagingFolderName", $stagingFolderName, "Process")
#[Environment]::SetEnvironmentVariable("stagingFolderName", $stagingFolderName, "Machine")
#$env:stagingFolderName = $stagingFolderName


Im unable to find a correct syntax or way to get the folderName.. 

feks. Pseudo: set myVar = powershell.exe "& {%scriptpath% -SOURCEFOLDERNAME %SourceFolderName% -SOURCEPATH %SourcePath% -TARGETHOST1 %TargetHost1% -TARGETHOST2 %TargetHost2%; exit $lastexitcode}" --> Won't execute..

(Not using the powershell plugin for the missing error return)

Kake

unread,
Mar 11, 2014, 5:10:08 AM3/11/14
to jenkins...@googlegroups.com
Help...

Daniel Beck

unread,
Mar 11, 2014, 3:58:36 PM3/11/14
to jenkins...@googlegroups.com
Use the 'Environment Injector' plugin. It allows you to load variable definition from a (Java .properties) file into the job environment.

Example:
--
First build step: Windows batch command:
echo foo=bar > env.properties

Second build step: Inject environment variables:
Properties File Path: env.properties
--
So just have your PS script write the properties file.
> --
> You received this message because you are subscribed to the Google Groups "Jenkins Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-use...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages