2016-10-20 10 views
1

Jenkins Job DSLプラグインを初めて使用して、より複雑なものになる前にいくつかの基本ジョブ "テンプレート"を作成しようとしています。GroovyスクリプトがJenkins DSLジョブからSlack通知パラメータを呼び出すことができない

JenkinsはWindows 2012サーバーで実行されています。 Jenkinsのバージョンは1.650で、Job DSLプラグインバージョン1.51を使用しています。

シードジョブをパラメータ化して、実行時にジョブDSLスクリプトの場所、生成されたジョブの名前、失敗通知用のスラックチャンネル、および失敗通知用の電子メールアドレスが含まれます。

最初の2つは問題ありません。たとえば、スクリプトでjob("${JOB_NAME}")を理解し、シードジョブを実行するときにジョブに入力した名前を使用するなど、groovyスクリプトのパラメータを呼び出すことができます。

しかし、私がSlackチャンネルで同じことをしようとすると、Groovyスクリプトは再生したくないようです。パラメータを呼び出そうとせずにスラックチャンネルを指定すると、うまく動作することに注意してください。

私の仕事のDSLスクリプトはこちら:

job("${JOB_NAME}") { 
    triggers { 
     cron("@daily") 
    } 
    steps { 
     shell("echo 'Hello World'") 
    } 
    publishers { 
    slackNotifier { 
     room("${SLACK_CHANNEL}") 
     notifyAborted(true) 
     notifyFailure(true) 
     notifyNotBuilt(false) 
     notifyUnstable(true) 
     notifyBackToNormal(true) 
     notifySuccess(false) 
     notifyRepeatedFailure(false) 
     startNotification(false) 
     includeTestSummary(false) 
     includeCustomMessage(false) 
     customMessage(null) 
     buildServerUrl(null) 
     sendAs(null) 
     commitInfoChoice('NONE') 
     teamDomain(null) 
     authToken(null) 
    } 
    } 
    logRotator { 
     numToKeep(3) 
     artifactNumToKeep(3) 
    publishers { 
     extendedEmail { 
      recipientList('[email protected]') 
      defaultSubject('Seed job failed') 
      defaultContent('Something broken') 
      contentType('text/html') 
      triggers { 
       failure() 
       fixed() 
       unstable() 
       stillUnstable { 
        subject('Subject') 
        content('Body') 
        sendTo { 
         developers() 
         requester() 
         culprits() 
        } 
       } 
      } 
     } 
    } 
    } 
} 

しかしシードジョブが失敗し、私にこの出力を与える開始:

Started by user 
Building on master in workspace D:\data\jenkins\workspace\tutorial-job-dsl-2 
Disk space threshold is set to :5Gb 
Checking disk space Now 
Total Disk Space Available is: 28Gb 
Node Name: master 
Running Prebuild steps 
Processing DSL script jobBuilder.groovy 
ERROR: (jobBuilder.groovy, line 10) No signature of method: javaposse.jobdsl.plugin.structs.DescribableContext.room() is applicable for argument types: (org.codehaus.groovy.runtime.GStringImpl) values: [#dev] 
Possible solutions: wait(), find(), dump(), grep(), any(), wait(long) 
[BFA] Scanning build for known causes... 
[BFA] No failure causes found 
[BFA] Done. 0s 
Started calculate disk usage of build 
Finished Calculation of disk usage of build in 0 seconds 
Started calculate disk usage of workspace 
Finished Calculation of disk usage of workspace in 0 seconds 
Finished: FAILURE 

これは私がGroovyので何かをしようとしたのは初めてです基本的なエラーだと思いますが、何か助けていただければ幸いです。

答えて

4

hm、Job DSLのバグです。JENKINS-39153を参照してください。

実際に値FOOを使用する場合は、テンプレート文字列構文"${FOO}"を使用する必要はありません。すべてのパラメータは、直接使用できる文字列変数です。

job(JOB_NAME) { 
    // ... 
    publishers { 
    slackNotifier { 
     room(SLACK_CHANNEL) 
     notifyAborted(true) 
     notifyFailure(true) 
     notifyNotBuilt(false) 
     notifyUnstable(true) 
     notifyBackToNormal(true) 
     notifySuccess(false) 
     notifyRepeatedFailure(false) 
     startNotification(false) 
     includeTestSummary(false) 
     includeCustomMessage(false) 
     customMessage(null) 
     buildServerUrl(null) 
     sendAs(null) 
     commitInfoChoice('NONE') 
     teamDomain(null) 
     authToken(null) 
    } 
    } 
    // ... 
} 

この構文はより簡潔であり、バグを引き起こしません。

+0

ありがとうございます!なぜ私はそれがかなり明確なカット説明であるので、私が検索していたときにそれを見つけられなかったのか分かりません。とにかくそれは今働くので、助けをありがとう。 – shaneoh

+0

私はバグを指摘してくれているだけでなく、文字列変数を直接使うことができるという事実を明確にする必要があります。 – shaneoh

+1

このバグはJobs DSL Pluginバージョン1.53以降で修正されています:https://github.com/jenkinsci/job-dsl-plugin/blob/81090b549b9c238f3fc09b2c06a7eaa2d69b3ea4/docs/Home.md#release-notes – bryanbraun

関連する問題