I just started learning DevOps and have a query. It might be very basic so please don't mind.
Setup: Jenkins, GIT, Groovy, Java are installed on single windows server.
My Goal is to write a Groovy script which will do following: 1. Execute GIT commands (on local GIT repository) to pull some data (result). 2. Take further actions based on above result.
Query: How to execute GIT commands in Groovy script? What all is needed? Would be great if someone can please share a sample basic script.
On a broader spectrum, what you want to achieve is just call linux commands from groovy, now regarding that:
There are 3 ways out of this, either you can just call the git commands from a shell script (since i understand you want to use jenkins for this), use some sort of git jenkins plugin, or if you absolutely want to use groovy for it, you can take a look at this question Groovy executing shell commands , to summarize, you can do the following:
def proc = "git command args".execute()
def b = new StringBuffer()
proc.consumeProcessErrorStream(b)
println proc.text
println b.toString()
on b you would have the errors of executing the linux command if there were any,
Best Regards,
check jenkins pipeline examples
https://jenkins.io/doc/pipeline/examples/
simplest pipeline with git:
node {
stage('Clone sources') {
git url: 'https://github.com/jfrogdev/project-examples.git'
}
}
git pipeline plugin doc:
https://jenkins.io/doc/pipeline/steps/git/
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