CI/CD - 环境搭建(1) - Jenkins Pipeline + Github

实现环境

通过Jenkins Job从Github获取代码并用Maven Build。

说明: 这里只用了一个Server, 用到的工具都安装在此

Jenkins安运行,请参考Jenkins安装

  1. 在Github创建一个Repository

    代码:

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    package artifactory;

    public class MavenSample {

    public static void main(String[] args) {
    // TODO Auto-generated method stub

    System.out.println("This for testing artifactory, github and jenkins");

    }
    }
  2. 安装/升级Maven,并做以下配置(Global Tool Configuration)

  3. 安装/升级Git,并做以下配置(Global Tool Configuration)
  4. 配置JDK(Global Tool Configuration)
  5. 创建一个Jenkins Pipeline Job

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    node {
    def mvnHome
    stage('Preparation') { // for display purposes

    // Get some code from a GitHub repository
    git 'https://www.github.com/yongfeiuall/artifactory-maven-example.git'
    // Get the Maven tool.
    // ** NOTE: This 'M3' Maven tool must be configured
    // ** in the global configuration.
    mvnHome = tool 'M3'
    }
    stage('Build') {
    // Run the maven build
    if (isUnix()) {
    sh "'${mvnHome}/bin/mvn' -Dmaven.test.failure.ignore clean package"
    } else {
    bat(/"${mvnHome}\bin\mvn" -Dmaven.test.failure.ignore clean package/)
    }
    }
    stage('Results') {
    archive 'target/*.jar'
    }
    }

  6. 运行Job

最基本的配置好了,接下来会配置当Github有Commit时Job自动运行。

唐胡璐 wechat
欢迎您扫一扫上面的微信公众号,订阅我的博客!
分享创造价值,您的支持将鼓励我继续前行!