【问题标题】:Pass a parameter into a Powershell script in Jenkins Pipeline将参数传递到 Jenkins Pipeline 中的 Powershell 脚本
【发布时间】:2020-10-08 18:32:24
【问题描述】:

之前有一些关于将 Jenkins 变量传递到 powershell 脚本的问题。但他们不为我工作。这可能是我运行 powershell 脚本的方式。 这是代码:

steps{
    script {

        echo "release file name: " + "$env:RELEASE_NAME"        
        powershell('''
            Write-Host "Deploy into WTC production"
            Write-Host "Release file: $env:RELEASE_NAME"        
            $finalPath = $env:RELEASE_NAME
            
            ...more powershell statements....
            
            ''')
        }

echo 语句返回带有版本和 .zip 扩展名的正确文件名 Write-Host 命令为版本名称返回一个空字符串

我尝试将 withEnv([releaseName=$env:RELEASE_NAME]) 添加到 powershell 脚本的顶部,如下所示:

withEnv([releaseName=$env:RELEASE_NAME])
powershell('''
                Write-Host "Deploy into WTC production"
                Write-Host "Release file: $env:releaseName"

但是由于:.文件无法编译。 如何将 RELEASE_NAME 变量传递到 powershell 脚本?

【问题讨论】:

    标签: powershell jenkins


    【解决方案1】:

    我想通了... withEnv 周围缺少双引号... 最终答案:

    script {
    
                        echo "release file name: " + "$RELEASE_NAME"
                        withEnv(["releaseName=$RELEASE_NAME"]){
                        powershell('''
                            Write-Host "Deploy into WTC production"
                            Write-Host "Release file: '$env:releaseName'"   
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-12-12
      • 1970-01-01
      • 2019-08-22
      • 1970-01-01
      相关资源
      最近更新 更多