小编olu*_*nt6的帖子

Jenkins Pipeline中的PowerShell环境变量为org.jenkinsci.plugins.workflow.cps.EnvActionImpl@1b69f5bb:VARIABLE_NAME

在Jenkins Pipeline中使用PowerShell时,是否有人遇到问题?当您尝试引入环境变量(例如$env:CHANGE_ID)时,它会得出类似的结果?

org.jenkinsci.plugins.workflow.cps.EnvActionImpl@1b69f5bb:VARIABLE_NAME
Run Code Online (Sandbox Code Playgroud)

看来其他人在这个问题上遇到了相同的问题,但是我不确定在那里是否得到了答案(他们展示了如何打印所有环境变量,但是没有展示如何在toString未实现时获取特定的环境变量): 在Jenkinsfile中检索env的所有属性

我的Jenkins管道文件:

pipeline {
  agent {
    node {
      label 'jenkins_managed_windows'
    }
  }

  stages {
    stage('SonarQube Analysis') {
      steps {
        powershell "dotnet sonarscanner begin /k:project-key /d:sonar.branch.name=$env:BRANCH_NAME"
      }
    }

    stage('Build') {
      steps {
        powershell 'dotnet build'
      }
    }

    stage('SonarQube End') {
      steps {
        powershell 'dotnet sonarscanner end'
      }
    }
  }
}
Run Code Online (Sandbox Code Playgroud)

包含环境变量的步骤运行为:

dotnet sonarscanner begin /k:project-key /d:sonar.branch.name=org.jenkinsci.plugins.workflow.cps.EnvActionImpl@54ee3a8:BRANCH_NAME
Run Code Online (Sandbox Code Playgroud) 有趣的是,如果我使用单引号:
powershell 'dotnet sonarscanner begin /k:project-key /d:sonar.branch.name=$env:BRANCH_NAME'
Run Code Online (Sandbox Code Playgroud) 它甚至根本不评估环境变量,而只是运行为:
dotnet sonarscanner begin /k:project-key /d:sonar.branch.name=$env:BRANCH_NAME
Run Code Online (Sandbox Code Playgroud)

powershell command-line jenkins jenkins-pipeline

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