美文网首页
jenkins test git check out

jenkins test git check out

作者: AppleLin_cdea | 来源:发表于2021-10-15 14:32 被阅读0次

2021年10月15日14:23:06 星期五
jenkins 使用 git checkout 的例子

代码

import org.jenkinsci.plugins.workflow.steps.FlowInterruptedException

class CMyClass implements Serializable
{
    def script
    
    def CMyClass(WorkflowScript)
    {
        this.script = WorkflowScript
    }
    
    def test_git_checkout()
    {
        script.sh '''#!/bin/bash -xe
            rm -rf demo_repo || yes
            mkdir demo_repo
        '''
        
        script.dir('demo_repo'){
            script.retry(3) {
                try {
                    script.checkout  scm: [$class: 'GitSCM', branches: [[name: 'master']], userRemoteConfigs: [[url: "apple@192.168.1.8:/home/apple/jenkins/demo_repo_main.git"]], \
                        compressionLevel:9, extensions: [[$class: 'CloneOption', depth: 100, noTags: true, reference: '', shallow: true, timeout: 30], [$class: "CheckoutOption", timeout: 30]] ]
                } catch (FlowInterruptedException err) {
                    script.error "git checkout demo_repo error! try again!"
                }
            }
        }
    } 
}

node_name='demo_slave'

node(node_name)
{
    stage('log')
    {
        myClassObj=new CMyClass(this)
        myClassObj.test_git_checkout()
    }
}

Console Output

14:11:14 Started by user apple
14:11:14 Running in Durability level: MAX_SURVIVABILITY
14:11:14 [Pipeline] Start of Pipeline
14:11:14 [Pipeline] node
14:11:14 Running on demo_slave in /home/apple/jenkins/workspace/demo
14:11:14 [Pipeline] {
14:11:15 [Pipeline] stage
14:11:15 [Pipeline] { (log)
14:11:15 [Pipeline] sh
14:11:15 + rm -rf demo_repo
14:11:15 + mkdir demo_repo
14:11:15 [Pipeline] dir
14:11:15 Running in /home/apple/jenkins/workspace/demo/demo_repo
14:11:15 [Pipeline] {
14:11:16 [Pipeline] retry
14:11:16 [Pipeline] {
14:11:16 [Pipeline] echo
14:11:16 try to checkout apple@192.168.1.8:/home/apple/jenkins/demo_repo_main.git
14:11:16 [Pipeline] checkout
14:11:16 WARNING: Unknown parameter(s) found for class type 'hudson.plugins.git.GitSCM': compressionLevel
14:11:16 No credentials specified
14:11:16 Cloning the remote Git repository
14:11:16 Using shallow clone with depth 100
14:11:16 Avoid fetching tags
14:12:29 Cloning repository apple@192.168.1.8:/home/apple/jenkins/demo_repo_main.git
14:12:29 > git init /home/apple/jenkins/workspace/demo/demo_repo # timeout=10
14:12:29 Fetching upstream changes from apple@192.168.1.8:/home/apple/jenkins/demo_repo_main.git
14:12:29 > git --version # timeout=10
14:12:29 > git fetch --no-tags --progress --depth=100 apple@192.168.1.8:/home/apple/jenkins/demo_repo_main.git +refs/heads/*:refs/remotes/origin/* # timeout=30
14:12:31 > git config remote.origin.url apple@192.168.1.8:/home/apple/jenkins/demo_repo_main.git # timeout=10
14:12:31 > git config --add remote.origin.fetch +refs/heads/*:refs/remotes/origin/* # timeout=10
14:11:18 Using shallow fetch with depth 100
14:11:19 Checking out Revision e5e2a4c79dc222125c07e69fc13e0980a7875373 (origin/master)
14:11:19 Commit message: "[bugfix][csv] add csv coverage to sev_test_result_sum.html"
14:12:31 > git config remote.origin.url apple@192.168.1.8:/home/apple/jenkins/demo_repo_main.git # timeout=10
14:12:31 Fetching upstream changes from apple@192.168.1.8:/home/apple/jenkins/demo_repo_main.git
14:12:31 > git fetch --no-tags --progress --depth=100 apple@192.168.1.8:/home/apple/jenkins/demo_repo_main.git +refs/heads/*:refs/remotes/origin/* # timeout=30
14:12:32 > git rev-parse origin/master^{commit} # timeout=10
14:12:32 > git config core.sparsecheckout # timeout=10
14:12:32 > git checkout -f e5e2a4c79dc222125c07e69fc13e0980a7875373 # timeout=30
14:12:32 > git rev-list --no-walk e5e2a4c79dc222125c07e69fc13e0980a7875373 # timeout=10
14:11:19 [Pipeline] }
14:11:19 [Pipeline] // retry
14:11:19 [Pipeline] }
14:11:19 [Pipeline] // dir
14:11:20 [Pipeline] }
14:11:20 [Pipeline] // stage
14:11:20 [Pipeline] }
14:11:20 [Pipeline] // node
14:11:20 [Pipeline] End of Pipeline
14:11:21 Finished: SUCCESS

总结

script.checkout scm: 只 checkout 目录demo_repo里面的内容,不会创建目录 demo_repo

相关文章

网友评论

      本文标题:jenkins test git check out

      本文链接:https://www.haomeiwen.com/subject/ivdmoltx.html