简体   繁体   中英

path variable for powershell in jenkins bat command

I want to execute my powershell script in my Jenkins pipeline. Therefore I use bat to call my .ps1 file

bat 'powershell "C:\\path\\to\\file\\script.ps1"'

Inside the powershell I need to use a specific path. Is there any way to deliver this path with something like:

bat 'powershell "C:\\path\\to\\file\\script.ps1"' -var PATH

Set up your environment inside the bat step before calling powershell:

bat """\
set PATH=....
powershell "C:\\path\\to\\file\\script.ps1"
""";

Inside the block you can reference you're pipeline variables with `${varName}`. So:

def myVar = "somePath"
bat """\
set PATH=%PATH%;${somePath}
powershell "C:\\path\\to\\file\\script.ps1"
""";

使用环境变量,如SET "INPT=C:\\\\path\\\\to\\\\file\\\\script.ps1" ,然后在powershell中使用。

不幸的是,在bat命令中不可能使用Pipeline Jobs变量

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM