2017-09-24 1 views
0

で環境変数を設定することができない、私はここでの例を参照しています私のテストでは、env変数が設定されていないように見えます。なぜなら、私のテストでは、envから取得しなければならない変数 "TEST_CONFIG_ROOT"の値が得られないと不平を言うからです。私ジェンキンスパイプラインにおける「TEST_CONFIG_ROOT」私は名前の環境変数を設定しようとしていますjenkinsfile

の下に私のjenkinsFileをご覧ください。

node('node1'){ 


     def buildInput; 

     echo 'Deploying my build' 
    if(!params.buildName) { 
     buildInput = input(
       id: 'userInput', message: 'What is the build name?', parameters: [ 
       [$class: 'StringParameterDefinition', defaultValue: 'abcd-1', description: 'Environment', name: 'buildName'] 
     ]) 
     } 
     buildToUse = params.buildName ? params.buildName : buildInput; 
     echo ("Env: "+buildToUse); 



    if ("${params.buildParam}" == 'prequal' || !params.buildParam){ 
     stage('Prequal') { 


     } 
    } 


    node('nodename'){ 

     if ("${params.buildParam}" == 'test' || !params.buildParam){ 
      withMaven(
        maven: 'M2Slave', 
        mavenSettingsConfig: 'MavenSettingsXML', 
        mavenLocalRepo: '${HOME}/.m2/repository') { 

       stage('Test') { 
        echo 'Testing my build' 
        echo " my work space is ${env.WORKSPACE}" 
        checkout scm 

        environment { 
         TEST_CONFIG_ROOT = '${env.WORKSPACE}/testsE2e/src/main/resources' 

        } 

    dir ('testsE2e'){ 
sh 'mvn clean verify surefire-report:report surefire-report:failsafe-report-only -Dtestngxml=testng.xml -Dhttp.proxyHost=proxy02.com -Dhttp.proxyPort=8080 -Dhttps.proxyHost=proxy02.com -Dhttps.proxyPort=8080 -Djavax.xml.accessExternalSchema=all' 
         } 

       } 

      } 
     } 

    } 

} 

私はまた、以下のようなシェルスクリプトを使用してエクスポートコマンドを実行しようとしたが、これも支援されていません。パイプラインのジョブが実行されたとき

echo " my work space is ${env.WORKSPACE}" 
sh 'export TEST_CONFIG_ROOT="${WORKSPACE}/testsE2e/src/main/resources"' 

ログのスニペットの下に検索:

[Pipeline] echo 
my work space is /usr/home/nodename/Jenkins/workspace/workspace/someName-RCZ4A4MA3GRP4PSVYT4HTVVIKU4J7TW2667CKTZU22CHR2CBEM5Q 
[Pipeline] dir 
Running in /usr/home/nodename/Jenkins/workspace/workspace/someName-RCZ4A4MA3GRP4PSVYT4HTVVIKU4J7TW2667CKTZU22CHR2CBEM5Q/testsE2e 
[Pipeline] { 
[Pipeline] sh 
[testsE2e] Running shell script 
+ mvn clean verify surefire-report:report surefire-report:failsafe-report-only -Dtestngxml=testng.xml -Dhttp.proxyHost=proxy02.com -Dhttp.proxyPort=8080 -Dhttps.proxyHost=proxy02.com -Dhttps.proxyPort=8080 -Djavax.xml.accessExternalSchema=all 
----- withMaven Wrapper script ----- 
Picked up JAVA_TOOL_OPTIONS: -Dmaven.ext.class.path="/usr/home/nodename/Jenkins/workspace/workspace/[email protected]p/withMaven00e87287/pipeline-maven-spy.jar" -Dorg.jenkinsci.plugins.pipeline.maven.reportsFolder="/usr/home/nodename/Jenkins/workspace/workspace/[email protected]p/withMaven00e87287" 
Apache Maven 3.3.9 (bb52d8502b132ec0a5a3f4c09453c07478323dc5; 2015-11-10T08:41:47-08:00) 
Maven home: /opt/maven/apache-maven-3.3.9 
Java version: 1.8.0_111, vendor: Oracle Corporation 
Java home: /opt/oracle/jdk1.8.0_111/jre 
Default locale: en_US, platform encoding: UTF-8 
OS name: "linux", version: "2.6.32-573.7.1.el6.x86_64", arch: "amd64", family: "unix" 
[jenkins-maven-event-spy] INFO generate /usr/home/nodename/Jenkins/workspace/workspace/[email protected]p/withMaven00e87287/maven-spy-20170924-225639-49.log ... 
[INFO] Scanning for projects... 
+1

よろしくお願いします。stackoverflow.com読みやすくするためにコード例を再フォーマットしてください。 – StephenKing

答えて

1

だから、これは働いていたものです私の場合は、他の人の言及についても言及しています。

withEnv(["TEST_CONFIG_ROOT=${env.WORKSPACE}/testsE2e/src/main/resources"]) { 
     dir ('testsE2e'){ 
    sh 'mvn clean verify surefire-report:report surefire-report:failsafe-report-only -Dtestngxml=testng.xml -Dhttp.proxyHost=proxy02.com -Dhttp.proxyPort=8080 -Dhttps.proxyHost=proxy02.com -Dhttps.proxyPort=8080 -Djavax.xml.accessExternalSchema=all' 
     } 
} 
2

私はあなたのスクリプトのもの(ドキュメントでPipeline Syntaxを参照)で宣言型のパイプラインを混合していると言うでしょう。

次のコードスニペットは、宣言型のものに属していますが、スクリプト1を持っている:

スクリプト化パイプラインで
environment { 
    TEST_CONFIG_ROOT = '${env.WORKSPACE}/testsE2e/src/main/resources' 
} 

、それは実際には少し簡単です:

env.TEST_CONFIG_ROOT = '${env.WORKSPACE}/testsE2e/src/main/resources' 
+0

ありがとう@StephenKing、私はあなたが上記のように試みたが、まだ運がない。 – stackoverflow

+0

それから私はあなたが何とかそれを台無しに言うと思います。あなたのパイプラインを最小限のバージョンに細分化して動作させるかどうかを確認してください。 – StephenKing

関連する問題