在Jenkins管道中执行npm-script(带变量)

问题描述 投票:0回答:1

Jenkins 2.107.3

我有一个管道詹金斯工作来执行下面的脚本,运行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: '[email protected]/postman.git'
    sh "npm install"
    try {
      sh "npm run api-tests" 
    } catch (Exception err) {
      currentBuild.result = 'UNSTABLE'
    }
  }
}

两种情况:

  1. Case Success:当我像作业参数一样声明${Environnement}“”
  2. Case Failure:是当我在作业${Environnement}中声明def Environnement = "DEV"时出现以下错误:
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个回答
2
投票

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

© www.soinside.com 2019 - 2024. All rights reserved.