2017-08-07 3 views
0

私はJenkins共有ライブラリを作成しています。groovyパッケージ/クラスをパイプラインにインポートするには?

私はコーダーではありません。そのため、私は多くのエラーにぶつかります。通常は解決方法はわかりません。

私の共有ライブラリの構造はそうのようになります。

[email protected] ~/src/company/pipeline_utils - (master) $ tree -f 
. 
├── ./1 
├── ./README.md 
├── ./functions.groovy 
├── ./src 
│   └── ./src/com 
│    ├── ./src/com/company 
│    │   ├── ./src/com/company/pipelines 
│    │   │   └── ./src/com/company/pipelines/standardPipeline.groovy 
│    │   └── ./src/com/company/utils 
│    │    ├── ./src/com/company/utils/Git.groovy 
│    │    ├── ./src/com/company/utils/SlackPostBuild.groovy 
│    │    ├── ./src/com/company/utils/dockerBuild.groovy 
│    │    ├── ./src/com/company/utils/dockerTest.groovy 
│    │    ├── ./src/com/company/utils/notifyEmail.groovy 
│    │    ├── ./src/com/company/utils/notifySlack.groovy 
│    │    ├── ./src/com/company/utils/pipeline.groovy 
│    │    └── ./src/com/company/utils/pipelineFunctions.groovy 
│    └── ./src/com/company-in-idea 
├── ./test_utils.groovy 
├── ./utils.groovy 
└── ./vars 
    ├── ./vars/standardPipeline.groovy 
    └── ./vars/utils.groovy 

パイプラインファイルはそうのようになります。

[email protected] ~/src/company/pipeline_utils - (master) $ cat ./vars/standardPipeline.groovy 
import com.company.utils.Git; 

def call(body) { 

     def config = [:] 
     body.resolveStrategy = Closure.DELEGATE_FIRST 
     body.delegate = config 
     body() 

     node { 
      // Clean workspace before doing anything 
      deleteDir() 

      try { 
       stage ('Clone') { 
        checkout scm 
             def committer = getCommitter() 
       } 
       stage ('Build') { 
        sh "echo 'building ${config.projectName} ...'" 
       } 
       stage ('Tests') { 
        parallel 'static': { 
         sh "echo 'shell scripts to run static tests...'" 
        }, 
        'unit': { 
         sh "echo 'shell scripts to run unit tests...'" 
        }, 
        'integration': { 
         sh "echo 'shell scripts to run integration tests...'" 
        } 
       } 
       stage ('Deploy') { 
        sh "echo 'deploying to server ${config.serverDomain}...'" 
        sh "echo Itai ganot" 
        sh "echo Itai" 
       } 
      } catch (err) { 
       currentBuild.result = 'FAILED' 
       throw err 
      } 
     } 
    } 

あなたは、私が「com.company.utilsをインポートするパイプラインファイルで見ることができます。 Gitの」Gitの機能のファイルがそうのようになります。

[email protected] ~/src/company/pipeline_utils - (master) $ cat ./src/com/company/utils/Git.groovy 
#!/usr/bin/env groovy 
package com.company.utils; 

    def sh_out(command) { 
    sh(returnStdout: true, script: command).trim() 
    } 

    def getCommitter(){ 
     node { 
     committer = this.sh_out('git show -s --format=\'%ce\' | tr -d "\'" | cut [email protected] -f1') 
     return committer 
     } 
    } 

    def getRepo(){ 
     node { 
      reponame = this.sh_out('basename $(git remote show -n origin | grep Push | cut -d: -f2- | rev | cut -c5- | rev)') 
      return reponame 
     } 
    } 

    void gitClean(){ 
     node { 
      this.sh_out(''' 
       sudo chown -R ubuntu:ubuntu . 
       if [ -d ".git" ]; then 
        sudo git reset --hard &>/dev/null 
        sudo git clean -fxd &>/dev/null 
        sudo git tag -d $(git tag) &>/dev/null 
       fi 
      || true ''') 
     } 
    } 
return this 

Jenkinsfileはそうのようになります。

@Library("company") _ 
standardPipeline { 
    projectName = "Project1" 
    serverDomain = "Project1 Server Domain" 
} 

私は仕事を実行すると、それが次のエラーで失敗します。私の知る限り理解し

java.lang.NoSuchMethodError: No such DSL method 'getCommitter' found among steps [AddInteractivePromotion, ArtifactoryGradleBuild, ArtifactoryMavenBuild, ConanAddRemote, ConanAddUser, InitConanClient, MavenDescriptorStep, RunConanCommand, ansiColor, ansiblePlaybook, archive...

、私はので、私は理由を理解していないパイプラインにgitのパッケージをインポートしましたこの機能は認識されません。

私が持っているもう一つの問題は、パイプラインは唯一src/com/company/pipelines/standardPipeline.groovyprojectDir/varsstandardPipeline.groovyファイルで「見える」とではないということです...私もVARSのディレクトリを削除しようとしたが、パイプラインが探し続けて...なぜですか?

私が間違っていることを知っていますか?

答えて

1

Gitクラスのメソッドを呼び出す代わりに、def committer = getCommitter()はgetCommitter()という名前のステップを探しているため、エラーを呼び出すものです。

def gitUtil = new Git() 
def committer = gitUtil.getCommitter() 
+0

ニース男性:

Referencing the documentation here、あなたはパイプラインファイル内でこのような何かを行う必要があります!どうもありがとう。 –

関連する問題