【问题标题】:Execute an npm-script (with variables) in a Jenkins pipeline在 Jenkins 管道中执行 npm 脚本(带变量)
【发布时间】:2019-01-04 09:16:08
【问题描述】:

詹金斯 2.107.3

我有一个管道 jenkins 作业来使用 npm run 执行下面的脚本

脚本

{
  "name": "jenkins-postman-automation",
  "version": "1.0.0",
  "description": "test project",
  "directories": {
    "test": "01-TNR-CLIMPLUS-NEWMAN"
  },
  "scripts": {
    "api-tests": "newman run 01-TNR-NEWMAN/01-TNR-CORE.postman_collection.json -e 99-Environnements/${Environnement} "
  },
  "author": "Reda",
  "dependencies": {
    "newman": "^3.5.2"
  }
}

管道:

node(){
  stage("testing"){
    deleteDir()

    echo 'git clone'
    git branch: 'master', url: 'git@git.ci/postman.git'
    sh "npm install"
    try {
      sh "npm run api-tests" 
    } catch (Exception err) {
      currentBuild.result = 'UNSTABLE'
    }
  }
}

两种情况:

  1. 案例成功:当我将${Environnement} 声明为工作参数时
  2. 案例失败:当我在工作def Environnement = "DEV" 中声明${Environnement} 时出现以下错误:
unable to read data from file "-e"
ENOENT: no such file or directory, open '-e'
  1. 我的问题:我想在我的工作中使用一个变量,所以我该怎么做,请帮忙!

它只在我使用声明式管道时有效,但现在不行。

【问题讨论】:

    标签: node.js jenkins npm jenkins-pipeline npm-scripts


    【解决方案1】:

    def Environnement = "DEV" 更改为env.Environnement="DEV"。 env.xxx 会将值设置到 shell 上下文的环境变量中,因此npm run api-tests 可以从 shell 上下文中获取值。

    【讨论】:

    • 感谢它在一个简单的 jenkins 管道中工作,但对 jenkins sharedlib 没有任何想法?
    猜你喜欢
    • 2021-10-19
    • 1970-01-01
    • 2021-12-14
    • 2019-09-24
    • 1970-01-01
    • 1970-01-01
    • 2021-12-17
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多