Back

Explore Courses Blog Tutorials Interview Questions
+1 vote
1 view
in DevOps and Agile by (29.3k points)

Are comments possible in a Jenkinsfile? If so, what's the syntax?

I am using the declarative pipeline syntax.

I want to comment out the "post" section below until my SMTP server is working.

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."

    }

  }

}

1 Answer

0 votes
by (19.4k points)

The Jenkinsfile is written in groovy which uses the Java (and C) form of comments. To make comments on the file you need to use the following way:

/* this

   is a

   multi-line comment */

// this is a single line comment

Related questions

Welcome to Intellipaat Community. Get your technical queries answered by top developers!

28.4k questions

29.7k answers

500 comments

94.6k users

Browse Categories

...