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 /保存 生成的结果)
  
  












![[StartingPoint][Tier1]Sequel](https://img-blog.csdnimg.cn/img_convert/48667436d3d84495d3fcb7e7933f7a86.jpeg)





