玖叶教程网

前端编程开发入门

Jenkins学习系列4-:pull git源码(jenkins拉取git代码原理)

创建git pull流水线任务:pull git源码

步骤:

  1. 编写Jenkinsfile上传Github)
  2. 创建凭据(Jenkinsfile项目或待拉取有密码的项目)
  3. 创建Jenkins工程,使用Jenkinsfile的gitlab(可使用凭据),自定义工程注释与参数
  4. 启动工程,查看Console Output输出

“新建任务”

配置任务

流水线脚本生成

脚本

 git credentialsId: 'pft-gitlab', url: 'http://host:port//ql-dev/perfect-digital-plant.git'

在gitlab的工程根目录下创建Jenkinsfile

 pipeline {
     agent any
     stages{
         stage('pull git demo') {
             steps{
                 //拉取代码,这里也是可以使用凭据的,为了方便没贴出来
                 git credentialsId: 'perfect-gitlab', url: 'http://host:port/ql-dev/perfect-digital-plant.git'
             }
         }
    }
 }

构建

点击#1-> Console Output

 Started by user Bruce Zou
 Obtained Jenkinsfile from git http://host:port//ql-dev/perfect-digital-plant.git
 Running in Durability level: MAX_SURVIVABILITY
 [Pipeline] Start of Pipeline
 [Pipeline] node
 Running on Jenkins in /data/bruce/jenkins/workspace/pull-digital-factory
 [Pipeline] {
 [Pipeline] stage
 [Pipeline] { (Declarative: Checkout SCM)
 [Pipeline] checkout
 The recommended git tool is: NONE
 using credential perfect-gitlab
 Cloning the remote Git repository
 Cloning repository http://host:port//ql-dev/perfect-digital-plant.git
  > git init /data/bruce/jenkins/workspace/pull-digital-factory # timeout=10
 Fetching upstream changes from http://host:port//ql-dev/perfect-digital-plant.git
  > git --version # timeout=10
  > git --version # 'git version 1.8.3.1'
 using GIT_ASKPASS to set credentials 
  > git fetch --tags --progress http://host:port//ql-dev/perfect-digital-plant.git +refs/heads/*:refs/remotes/origin/* # timeout=10
  > git config remote.origin.url http://shost:port//ql-dev/perfect-digital-plant.git # timeout=10
  > git config --add remote.origin.fetch +refs/heads/*:refs/remotes/origin/* # timeout=10
 Avoid second fetch
  > git rev-parse refs/remotes/origin/master^{commit} # timeout=10
 Checking out Revision 9a28de3e6ae72344003e3f1953279e0540836ca2 (refs/remotes/origin/master)
  > git config core.sparsecheckout # timeout=10
  > git checkout -f 9a28de3e6ae72344003e3f1953279e0540836ca2 # timeout=10
 Commit message: "Update Jenkinsfile"
 First time build. Skipping changelog.
 [Pipeline] }
 [Pipeline] // stage
 [Pipeline] withEnv
 [Pipeline] {
 [Pipeline] stage
 [Pipeline] { (pull git demo)
 [Pipeline] git
 The recommended git tool is: NONE
 using credential perfect-gitlab
  > git rev-parse --resolve-git-dir /data/bruce/jenkins/workspace/pull-digital-factory/.git # timeout=10
 Fetching changes from the remote Git repository
  > git config remote.origin.url http://host:port/ql-dev/perfect-digital-plant.git # timeout=10
 Fetching upstream changes from http://host:port//ql-dev/perfect-digital-plant.git
  > git --version # timeout=10
  > git --version # 'git version 1.8.3.1'
 using GIT_ASKPASS to set credentials 
  > git fetch --tags --progress http://shost:port/0/ql-dev/perfect-digital-plant.git +refs/heads/*:refs/remotes/origin/* # timeout=10
  > git rev-parse refs/remotes/origin/master^{commit} # timeout=10
 Checking out Revision 9a28de3e6ae72344003e3f1953279e0540836ca2 (refs/remotes/origin/master)
  > git config core.sparsecheckout # timeout=10
  > git checkout -f 9a28de3e6ae72344003e3f1953279e0540836ca2 # timeout=10
  > git branch -a -v --no-abbrev # timeout=10
  > git checkout -b master 9a28de3e6ae72344003e3f1953279e0540836ca2 # timeout=10
 Commit message: "Update Jenkinsfile"
 [Pipeline] }
 [Pipeline] // stage
 [Pipeline] }
 [Pipeline] // withEnv
 [Pipeline] }
 [Pipeline] // node
 [Pipeline] End of Pipeline
 Finished: SUCCESS

发表评论:

控制面板
您好,欢迎到访网站!
  查看权限
网站分类
最新留言