perform Git checkout using Groovy script

+4 votes

I have been trying to perform git checkout operation in Jenkins using Groovy. I am executing it under system groovy script.

Can anyone help me with the above query?

May 1, 2018 in DevOps Tools by Atul
• 10,240 points
32,321 views
@Atul, why are you using Groovy? I just want to understand the whole picture.

4 answers to this question.

0 votes

Try this:

You can just invoke git through groovy:

 If you want to clone you need to execute

 ["git", "clone", "repo.org.com/gitlab/proj/repo.git", "/Baseline/Package/Logistics/"].execute()

and then you can checkout to the particular branch.

I hope it will help you.

answered May 1, 2018 by shubham
• 7,340 points
0 votes
You can just invoke git through groovy

["git", "checkout", "master"].execute()
answered Aug 2, 2018 by lina
• 8,220 points
0 votes

Try this:

def checkoutGitRepository(path, url, branch, credentialsId = null, poll = true, timeout = 10, depth = 0){
    dir(path) {
        checkout(
            changelog:true,
            poll: poll,
            scm: [
                $class: 'GitSCM',
                branches: [[name: "*/${branch}"]],
            doGenerateSubmoduleConfigurations: false,
            extensions: [
                [$class: 'CheckoutOption', timeout: timeout],
                [$class: 'CloneOption', depth: depth, noTags: false, reference: '', shallow: depth > 0, timeout: timeout]],
            submoduleCfg: [],
            userRemoteConfigs: [[url: url, credentialsId: credentialsId]]]
        )
        sh(returnStdout: true, script: 'git rev-parse HEAD').trim()
    }
}
answered Dec 6, 2018 by akaash
0 votes

To do git commit:

def getGitCommit() {
    git_commit = sh (
        script: 'git rev-parse HEAD',
        returnStdout: true
    ).trim()
    return git_commit
}
answered Dec 6, 2018 by Vaidya
Hi,

Can we add reviewers suing grovvy code ?

If some one knows pls help

Thanks

Kannan
What exactly are you trying to do?

Related Questions In DevOps Tools

0 votes
1 answer

How to Replicate the Artifacts between two Jfrog Artifactories by using CURL or jfrog rt (Rest API)

Yes and no, It's a bit complex ...READ MORE

answered Mar 27, 2018 in DevOps Tools by Atul
• 10,240 points
1,277 views
0 votes
1 answer

running comands as non-root user while using docker-maven plugin

Docker needs root access therefore maven commands ...READ MORE

answered Apr 30, 2018 in DevOps Tools by ajs3033
• 7,300 points
2,675 views
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer

Logs in phoenix web app deployed using edeliver

The newer versions of edilever and distillery ...READ MORE

answered Jun 19, 2018 in DevOps Tools by ajs3033
• 7,300 points
730 views
+15 votes
2 answers

Git management technique when there are multiple customers and need multiple customization?

Consider this - In 'extended' Git-Flow, (Git-Multi-Flow, ...READ MORE

answered Mar 27, 2018 in DevOps & Agile by DragonLord999
• 8,450 points
3,460 views
+2 votes
1 answer
0 votes
3 answers
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP