Answer a question

I have written a simple script via PowerShell to gather some files and zip them into one folder, lets call it Script.ps1. I want to make the script run every time Jenkins does a new build, however I also would like the name of the zip file to be the BUILD_NUMBER.

How can I create a variable in PowerShell that is Jenkins's current build number? As of the moment I am calling the Script.ps1 in the execute shell section of configuration.

Answers

You can add arguments to your Script.ps1. Just use Param at the top of the script:

Param( $BuildNumber ) #must be first statement in script
# your current script goes here

then you can call the script passing BUILD_NUMBER as argument from Jenkins. Refer to this question for calling Powershell script with argument.

Logo

CI/CD社区为您提供最前沿的新闻资讯和知识内容

更多推荐