Saturday, October 26, 2013

Passing Jenkins Build Variables Using PowerShell's "invoke-command" Cmdlet

Sometimes it is the small things that can take up most of the time when I'm working with PowerShell scripts in Jenkins. I call this the PowerShell Pareto Principle! Usually it is a syntax issue that bites me, but recently I had trouble passing in build variables using the invoke-command cmdlet. This example should clear things up if you encounter the same perplexities which stumped me.

invoke-command your_remote_servername {param(
   [String]$BUILDID,
   [String]$BUILDNUM
   )
   write-host JENKINS-$BUILDID-BUILD$BUILDNUM} -ArgumentList $env:BUILD_ID,$env:BUILD_NUMBER

By using the ArgumentList argument of invoke-command you can pass in outside variables into the Jenkins PowerShell plugin, executing code targeted for a remote server running the WinRM service. That's Hot!™

2 comments:

  1. Thank you for this valuable information. It was really helpful.

    IOSH safety course in Kuwait

    ReplyDelete
  2. very nice articles ....use full information...and thanks for sharing....
    IOSH safety course in Kuwait

    ReplyDelete