I'm trying to create my first Groovy script for Jenkins:
After looking here https://jenkins.io/doc/book/pipeline/, I created this:
node { stages { stage('HelloWorld') { echo 'Hello World' } stage('git clone') { git clone "ssh://[email protected]/myrepo.git" } } }
However, I'm getting:
java.lang.NoSuchMethodError: No such DSL method "stages" found among steps
What am I missing?
Also, how can I pass my credentials to the Git Repository without writing the password in plain text?
Job DSL was one of the first popular plugins for Jenkins which allows managing configuration as code and many other plugins dealing with this aspect have been created since then, most notably the Jenkins Pipeline and Configuration as Code plugins.
A Jenkinsfile is a text file that contains the definition of a Jenkins Pipeline and is checked into source control. Consider the following Pipeline which implements a basic three-stage continuous delivery pipeline.
You are confusing and mixing Scripted Pipeline
with Declarative Pipeline
, for complete difference see here. But the short story:
So, if we look at your script, you first open a node
step, which is from scripted pipelines. Then you use stages
which is one of the directives of the pipeline
step defined in declarative pipeline
. So you can for example write:
pipeline { ... stages { stage('HelloWorld') { steps { echo 'Hello World' } } stage('git clone') { steps { git clone "ssh://[email protected]/myrepo.git" } } } }
So if you want to use declarative pipeline
that is the way to go.
If you want to scripted pipeline
, then you write:
node { stage('HelloWorld') { echo 'Hello World' } stage('git clone') { git clone "ssh://[email protected]/myrepo.git" } }
E.g.: skip the stages block.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With