Jenkins 和常用工具集成
一、 Jenkins Linux shell集成和Jenkins参数集成
1.Jenkins Linux shell集成主要作用是实现脚本的执行可视化
创建一个 shell 模块的自由风格的job
脚本:
#!/bin/sh user=`whoami` if [ $user == 'deploy' ] then echo "Hello, my name is $user" else echo "Sorry, I am not $user" fi ip addr cat /etc/system-release free -m df -h py_cmd=`which python` $py_cmd --version
2.Jenkins 参数集成:通过传入不通的参数,可以实现不同环境,不同版本,不同逻辑的执行效果。
脚本
#!/bin/sh echo "Current deploy environment is $deploy_env" echo "The build is $version" echo "The paasword is $pass" if $bool then echo "Request is approved" else echo "Request is rejected" fi
二、 Jenkins git 和 maven 集成
1.jenkins和git 集成
2.jenkins和maven集成
a.先下载 maven的安装包
[root@jenkins ~]# wget https://mirrors.tuna.tsinghua.edu.cn/apache/maven/maven-3/3.6.3/binaries/apache-maven-3.6.3-bin.tar.gz --2021-02-22 17:02:31-- https://mirrors.tuna.tsinghua.edu.cn/apache/maven/maven-3/3.6.3/binaries/apache-maven-3.6.3-bin.tar.gz 正在解析主机 mirrors.tuna.tsinghua.edu.cn (mirrors.tuna.tsinghua.edu.cn)... 101.6.8.193, 2402:f000:1:408:8100::1 正在连接 mirrors.tuna.tsinghua.edu.cn (mirrors.tuna.tsinghua.edu.cn)|101.6.8.193|:443... 已连接。 已发出 HTTP 请求,正在等待回应... 200 OK 长度:9506321 (9.1M) [application/x-gzip] 正在保存至: “apache-maven-3.6.3-bin.tar.gz” 100%[========================================================================================================================================>] 9,506,321 23.4MB/s 用时 0.4s 2021-02-22 17:02:32 (23.4 MB/s) - 已保存 “apache-maven-3.6.3-bin.tar.gz” [9506321/9506321]) [root@jenkins ~]# tar xvf apache-maven-3.6.3-bin.tar.gz -C /opt/ [root@jenkins bin]# pwd /opt/apache-maven-3.6.3/bin [root@jenkins bin]# ./mvn --version Apache Maven 3.6.3 (cecedd343002696d0abb50b32b541b8a6ba2883f) Maven home: /opt/apache-maven-3.6.3 Java version: 1.8.0_282, vendor: Red Hat, Inc., runtime: /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.282.b08-1.el7_9.x86_64/jre Default locale: zh_CN, platform encoding: UTF-8 OS name: "linux", version: "3.10.0-957.21.3.el7.x86_64", arch: "amd64", family: "unix"
构建成功,war包位置为:
/var/lib/jenkins/workspace/maven-freestyle-job/target/Java-war-dev.war
三、 Jenkins 和 ansible 集成
脚本
View Code
致此,Jenkins + ansible的集成完成。