jenkins 克隆gitlab代码到指定目录


  • 添加支持的插件
    • Manage Jenkins -> Manage Plugins
    • 添加gitlabel 和 git 插件
  • 创建credential
    • Manage Jenkins -> Manage Credentials
      image
      image
  • 创建pipeline
    • new item -> pipeline
    • pipline script 填入一下内容, 修改credential的id和git的url以及存放的目录
      pipeline {
        agent any
        stages {
      	stage('create directory') {
      		steps {
      			sh 'sudo mkdir -p /gitlabel/test-project'
      		}
      	}
      	stage('git pull') {
      	  steps {
      		  checkout(
      			[
      			  $class: 'GitSCM',
      			  branches: [[name: '*/master']],
      			  extensions: [
      				[
      				  $class: 'CloneOption', timeout: 15
      				],
      				[
      				  $class: 'RelativeTargetDirectory',
      				  relativeTargetDir: '/gitlabel/test-project'
      				]
      			  ],
      			  userRemoteConfigs: [[
      				credentialsId: 'gitlab_credential',
      				url: 'git@xxxxxxx/test-project.git'
      			  ]]
      			]
      		  )
      	  }
      	}
      	stage('maven build') {
      		steps {
      			sh 'cd /gitlabel/test-project && mvn clean package -DskipTests'
      		}
      	}
        }
      
    }


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM