Jenkins (三) - 拉取编译

Jenkins (三) - 拉取编译

通过Jenkins平台 git 拉取github上项目,通过maven编译并打包。

Jenkins 安装 git 插件

Manager Jenkins -> Plugins -> Available plugins -> Git

打包编译检验

FressStyle 风格编译
  • New Item
  • 输入 item name Spring-Cloud-17-DEV
  • 选择 Freestyle project
  • Source Code Management
  • Git:
    - Repository URL: Spring-Cloud-17

如果遇到如下错误,则需设置github 访问token - github access token, 文末有如何设置

Failed to connect to repository : Command "git ls-remote -h -- https://github.com/fernado/spring-cloud-17.git HEAD" returned status code 128:
stdout:
stderr: remote: Support for password authentication was removed on August 13, 2021.
remote: Please see https://docs.github.com/get-started/getting-started-with-git/about-remote-repositories#cloning-with-https-urls for information on currently recommended modes of authentication.
fatal: Authentication failed for 'https://github.com/fernado/spring-cloud-17.git/'

在这里插入图片描述
Credentials - add

Username: ${github 登录账号}
Password: ${github access token}

在这里插入图片描述

  • 设置 branch
    在这里插入图片描述
  • 启动 Build Now
    在这里插入图片描述
    在这里插入图片描述
Pipeline 风格编译

New Item

  • 输入 item name: mockito-demo
  • 选择 Pipeline

在这里插入图片描述

  • 编写 pipeline 脚本
    Jenkins Pipeline 配置脚本生成工具地址 ${JENKINSIP:PORT}/job/mockito-demo/pipeline-syntax/ eg. http://192.168.56.102:8080/job/mockito-demo/pipeline-syntax/
node {
    def mvnHome
    stage('Preparation') { // for display purposes

        checkout scmGit(branches: [[name: '*/main']], extensions: [], userRemoteConfigs: [[credentialsId: 'fernado', url: 'https://github.com/fernado/mockito-demo.git']])
        mvnHome = tool 'maven396'
    }
    stage('Build') {
        // Run the maven build
        withEnv(["MVN_HOME=$mvnHome"]) {
            if (isUnix()) {
                sh '"$MVN_HOME/bin/mvn" -Dmaven.test.failure.ignore clean package'
            } else {
                bat(/"%MVN_HOME%\bin\mvn" -Dmaven.test.failure.ignore clean package/)
            }
        }
    }
    stage('Results') {
        echo 'no archiving'
        junit '**/target/surefire-reports/TEST-*.xml'
        //archiveArtifacts 'target/*.jar'
    }
}
  • 验证 Build Now
    在这里插入图片描述

在这里插入图片描述

设置 github access token

  • Settings -> <> Developer settings -> GitHub Apps -> Personal access tokens -> Token(classic
  • Personal access tokens (classic) -> Generate new token ->
    Generate new token (classic)
  • Note: 给一个标签说明这个access token 用于什么地方
  • Expiration: No expiration
  • Select scopes: 看情况选择
  • Generate token 生成 access token (记得copy /保存 生成的结果)
    在这里插入图片描述
    在这里插入图片描述
  • 3
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值