Sind Kommentare in einem Jenkinsfile möglich? Wenn ja, wie lautet die Syntax?
Ich verwende die deklarative Pipeline-Syntax.
Ich möchte den Abschnitt "Beitrag" unten auskommentieren, bis mein SMTP-Server funktioniert.
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."
}
}
}
Das Jenkinsfile ist in Groovy geschrieben und verwendet die Java (und C) -Form von Kommentaren:
/* this
is a
multi-line comment */
// this is a single line comment
Sie können für jede Zeile einen Block (/ *** /) oder einen einzeiligen Kommentar (//) verwenden. Sie sollten "#" im Befehl sh verwenden.
Blockkommentar
/*
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."
}
}
*/
Single Line
// 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."
// }
// }
Kommentar in 'sh' Befehl
stage('Unit Test') {
steps {
ansiColor('xterm'){
sh '''
npm test
# this is a comment in sh
'''
}
}
}
Kommentare funktionieren in allen üblichen Java/Groovy-Formen, aber Sie können verwenden derzeit groovydoc
, um Ihre Jenkinsfile
(s) zu verarbeiten.
Erstens drosselt groovydoc
Dateien ohne Erweiterungen mit dem wunderbaren Fehler
Java.lang.reflect.InvocationTargetException
at Sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at Sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.Java:62)
at Sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.Java:43)
at Java.lang.reflect.Method.invoke(Method.Java:498)
at org.codehaus.groovy.tools.GroovyStarter.rootLoader(GroovyStarter.Java:109)
at org.codehaus.groovy.tools.GroovyStarter.main(GroovyStarter.Java:131)
Caused by: Java.lang.StringIndexOutOfBoundsException: String index out of range: -1
at Java.lang.String.substring(String.Java:1967)
at org.codehaus.groovy.tools.groovydoc.SimpleGroovyClassDocAssembler.<init>(SimpleGroovyClassDocAssembler.Java:67)
at org.codehaus.groovy.tools.groovydoc.GroovyRootDocBuilder.parseGroovy(GroovyRootDocBuilder.Java:131)
at org.codehaus.groovy.tools.groovydoc.GroovyRootDocBuilder.getClassDocsFromSingleSource(GroovyRootDocBuilder.Java:83)
at org.codehaus.groovy.tools.groovydoc.GroovyRootDocBuilder.processFile(GroovyRootDocBuilder.Java:213)
at org.codehaus.groovy.tools.groovydoc.GroovyRootDocBuilder.buildTree(GroovyRootDocBuilder.Java:168)
at org.codehaus.groovy.tools.groovydoc.GroovyDocTool.add(GroovyDocTool.Java:82)
at org.codehaus.groovy.tools.groovydoc.GroovyDocTool$add.call(Unknown Source)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.Java:48)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.Java:113)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.Java:125)
at org.codehaus.groovy.tools.groovydoc.Main.execute(Main.groovy:214)
at org.codehaus.groovy.tools.groovydoc.Main.main(Main.groovy:180)
... 6 more
... und zweitens, soweit ich Javadoc-artige Aussagen zu Beginn eines groovy
Skripts machen kann, werden diese ignoriert. Selbst wenn Sie also Ihr Jenkinsfile
in Jenkinsfile.groovy
kopieren/umbenennen, erhalten Sie keine besonders nützliche Ausgabe.
Ich möchte in der Lage sein, a
/**
* Document my Jenkinsfile's overall purpose here
*/
kommentar am Anfang meines Jenkinsfile. Noch kein Glück.
groovydoc
wird Klassen und Methoden verarbeiten, die in Ihrem Jenkinsfile
definiert sind, wenn Sie -private
an den Befehl übergeben.