将参数传递到Jenkins管道中的Powershell脚本中

将参数传递到Jenkins管道中的Powershell脚本中,powershell,jenkins,Powershell,Jenkins,前面有一些关于将Jenkins变量传递到powershell脚本的问题。但他们不是为我工作。这可能是我运行powershell脚本的方式。 代码如下: steps{ script { echo "release file name: " + "$env:RELEASE_NAME" powershell(''' Write-Host "Deploy into WTC

前面有一些关于将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\u NAME])
添加到powershell脚本的顶部,如下所示:

withEnv([releaseName=$env:RELEASE_NAME])
powershell('''
                Write-Host "Deploy into WTC production"
                Write-Host "Release file: $env:releaseName"
但文件未编译,因为:。 如何将RELEASE\u NAME变量传递到powershell脚本中?

我找到了答案。。。 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'"