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
34,256 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

Why does Git keep asking for my password when using Azure DevOps, and how can I fix it?

Reason: When authentication isn't set up correctly or ...READ MORE

answered Dec 6, 2024 in DevOps Tools by Gagana
• 7,530 points
48 views
0 votes
0 answers

What are the challenges with using Git submodules in Azure DevOps, and how can they be mitigated?

What are the challenges with using Git ...READ MORE

Dec 10, 2024 in DevOps Tools by Anila
• 5,040 points
56 views
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,809 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
3,060 views
0 votes
1 answer
+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
4,086 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