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'
      		}
      	}
        }
      
    }
posted @ 2022-02-21 15:19  cc-31415926  阅读(1071)  评论(0编辑  收藏  举报