You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Jenkins Pipeline阶段未执行Steps即失败且无报错日志

问题排查与解决方案

首要问题:Pipeline语法结构错误

你的stage代码违反了Jenkins Pipeline的规范:environment块必须作为stage的直接子元素,不能被echo这类语句打断。当前代码中你先执行echo再定义environment,会导致Pipeline语法解析失败,直接终止阶段执行,既不会进入steps,也触发不了post步骤。

修正后的代码示例

stage('42 Crunch Conformance Scan') {
  // environment必须放在stage顶层
  environment {
    http_proxy = '****'
    https_proxy = '****'
  }
  steps {
    echo "*** Started 42 Crunch Conformance Scan ***"
    echo "Proxy Set"
    
    withCredentials([string(credentialsId: '42crunch-api-token', variable: 'API_KEY')]) {
      // 激活NodeJS环境(替换成你在NodeJS插件中配置的安装名称)
      nodejs('NodeJS-18.x') {
        // 开启shell调试日志,方便定位问题
        sh 'set -x; newman -version'
        // 用单引号包裹脚本,让shell自行解析变量,避免Groovy提前替换引发的问题
        sh '''
          newman run integration/42crunch/${appName}42Crunch.postman_collection.json \
          -e integration/smoke/${appName}ApigeeSmokeTest.postman_environment.json \
          --env-var runningOnPipeline=yes \
          --env-var x-api-key=${API_KEY}
        '''
      }
    }
  }
  post {
    failure {
      archiveArtifacts artifacts: '**/newman/*.html', fingerprint: true
    }
  }
}

其他关键排查点

  • NodeJS环境激活:newman是通过NodeJS插件安装的,必须用nodejs('配置名称')包裹执行步骤,确保Jenkins能找到newman命令。
  • 文件路径验证:在steps中添加sh 'ls -la integration/42crunch/',确认集合文件和环境文件存在且路径正确。
  • 代理生效检查:在sh脚本中加入echo $http_proxy,验证代理变量是否传递到shell进程。
  • 日志调试:保留set -x参数,能看到shell执行的每一步细节,快速定位变量替换、命令执行失败的原因。

内容的提问来源于stack exchange,提问作者scottyboombox

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.26 05:05:33