2017-02-18 39 views
23

在Jenkinsfile中可以評論嗎?如果是這樣,語法是什麼?可以將評論添加到Jenkinsfile中嗎?

我正在使用聲明式管道語法。

我想註釋掉下面的「post」部分,直到我的SMTP服務器工作。

pipeline { 

    agent { label 'docker-build-slave' } 

    environment { 
    IMAGE = 'registry.gitlab.com/XXXXX/bible-server' 
    DOCKER_REGISTRY_CREDENTIALS = credentials('DOCKER_REGISTRY_CREDENTIALS') 
    } 

    options { 
    timeout(10) 
    } 

    stages { 

    stage('Test') { 
     steps { 
     sh 'yarn' 
     sh 'npm test' 
     } 
    } 

    stage('Build') { 
     when { 
     branch '*/master' 
     } 
     steps { 
     sh 'docker login -u ${DOCKER_REGISTRY_CREDENTIALS_USR} -p ${DOCKER_REGISTRY_CREDENTIALS_PSW} registry.gitlab.com' 
     sh 'docker build -t ${IMAGE}:${BRANCH_NAME} .' 
     sh 'docker push ${IMAGE}:${BRANCH_NAME}' 
     } 
    } 

    stage('Deploy') { 
     when { 
     branch '*/master' 
     } 
     steps { 
     echo 'Deploying ..' 
     } 
    } 
    } 

    post { 
    success { 
     mail to: "[email protected]", subject:"SUCCESS: ${currentBuild.fullDisplayName}", body: "Yay, we passed." 
    } 
    failure { 
     mail to: "[email protected]", subject:"FAILURE: ${currentBuild.fullDisplayName}", body: "Boo, we failed." 
    } 
    } 
} 

回答

52

的Jenkinsfile是寫在使用註釋的Java語言(C)形式常規:

/* this 
    is a 
    multi-line comment */ 

// this is a single line comment 
+0

我使用聲明流水線上jenkinsfile的SH部分的內部和失敗,或許它在塊級別上工作。 'pipeline {stage}('Set Tagging'){ steps { sh''' echo「env.m_time ='$ m_time'」> $ {params_file} echo「env.m_comp_tag ='$ { BRANCH_NAME} _ $ {m_time} _ $ {BUILD_NUMBER}'「>> $ {params_file} /* echo」env.docker_ws ='/ usr/local/lib/node_modules/$ {repo}'「>> $ {params_file } */ '''<' 導致錯誤/ bash權限錯誤 – Chen

+3

在'sh'節中,您需要使用shell註釋字符:'#' – BMitch