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
8,563 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
• 6,890 points
0 votes
You can just invoke git through groovy

["git", "checkout", "master"].execute()
answered Aug 2, 2018 by lina
• 8,160 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
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,280 points
624 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,280 points
55 views
+13 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 26, 2018 in DevOps & Agile by DragonLord999
• 8,380 points
264 views
0 votes
1 answer
0 votes
3 answers