小编Ram*_*sad的帖子

在 Powershell 脚本中传递 Jenkins 环境变量

我想在 powershell 脚本中使用 jenkins 环境变量。这里 ${destination} 在 powershell 脚本中为空。无法确定我在做什么错误。请帮忙

!/bin/groovy

管道{

agent {
    label {
        label ""
        customWorkspace "C:\\Jenkins\\workspace"
    }
}
environment {       
    
    def destination=''
}
options {
    timestamps()
    timeout(time: 60, unit: 'MINUTES')      
    skipDefaultCheckout(true)
    disableConcurrentBuilds()
 }

stages {
    
    stage('TEST') 
    {     
        steps {
                script{
                    destination="\\\\SERVERNAME\\d\$"
                }
                echo "${destination}"
                
                powershell '''
                
                    $destinationPath ="${destination}"
                     
                    write-host $destinationPath
                    
                    write-host "test3" '''
                
            }  
    }
}
post {
    always {
        deleteDir()         
    }   
Run Code Online (Sandbox Code Playgroud)

}

declarative jenkins jenkins-pipeline

5
推荐指数
1
解决办法
6761
查看次数

标签 统计

declarative ×1

jenkins ×1

jenkins-pipeline ×1