如果想通过curl命令,远程发送请求的方式触发Jenkins进行调度,需要关闭全局安全设置
中的防止跨站点请求伪造
在安装Jenkins时,需要提前将JDK、Maven以及Git环境安装在你的机器中。下面是一些配置细节:
# 安装命令 $ yum install java-1.8.0-openjdk-1.8.0.191.b12-0.el7_5.x86_64 $ yum install java-1.8.0-openjdk-devel-1.8.0.191.b12-0.el6_10.x86_64 # 查看命令 [root@longsl jvm]# rpm -qa | grep java java-1.8.0-openjdk-1.8.0.191.b12-0.el6_10.x86_64 java-1.8.0-openjdk-headless-1.8.0.191.b12-0.el6_10.x86_64 java-1.8.0-openjdk-devel-1.8.0.191.b12-0.el6_10.x86_64
sudo yum install -y git
git 1.8.3.1
/usr/bin/git
$ wget http://mirrors.sonic.net/apache/maven/maven-3/3.6.0/binaries/apache-maven-3.6.0-bin.tar.gz # Ensure JAVA_HOME environment variable is set and points to your JDK installation $ vim /etc/profile export JAVA_HOME="/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.191.b12-0.el6_10.x86_64" export PATH="$JAVA_HOME/bin:$PATH" export MAVEN_HOME="/opt/maven-3.6" export PATH="$MAVEN_HOME/bin:$PATH" $ tar xzvf apache-maven-3.6.0-bin.tar.gz # 查看命令 [root@longsl maven-3.6]# mvn --version Apache Maven 3.6.0 (97c98ec64a1fdfee7767ce5ffb20918da4f719f3; 2018-10-25T02:41:47+08:00) Maven home: /opt/maven-3.6 Java version: 1.8.0_191, vendor: Oracle Corporation, runtime: /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.191.b12-0.el6_10.x86_64/jre Default locale: en_US, platform encoding: UTF-8 OS name: "linux", version: "4.16.12-1.el6.elrepo.x86_64", arch: "amd64", family: "unix"
进入Jenkins官方下载站点 https://jenkins.io/download/
$ wget http://mirrors.jenkins.io/war-stable/latest/jenkins.war
通过Apache Tomcat的方式启动Jenkins
将Jenkins.war包移到$TOMCAT_HOME/webapps目录下,重启Tomcat,然后访问 http://localhost:8080/jenkins/
通过java命令行的方式启动Jenkins.war包
$ mkdir -p /var/log/jenkins/ /var/cache/jenkins/ /root/jenkins/ $ sudo nohup /etc/alternatives/java -Djava.awt.headless=true -DJENKINS_HOME=/root/jenkins -jar /root/jenkins/jenkins.war --logfile=/var/log/jenkins/jenkins.log --webroot=/var/cache/jenkins/war --httpPort=8082 --debug=5 --handlerCountMax=100 --handlerCountMaxIdle=20 &
上面通过java命令来启动的好处:Jenkins运行和Tomcat服务器进行分离,另外可以在启动的时候自定义端口号和日志输出路径等。
cat /root/jenkins/secrets/initialAdminPassword
通过git来管理源码,这里填入Repositories中的URL和Credentials
Root POM:deploy/pom.xml
Goals and options:clean package -Pdev
sudo rm -rf /usr/app/tomcat/webapps/deploy && sudo cp -f ${WORKSPACE}/deploy/target/deploy.war /usr/app/tomcat/webapps && sudo systemctl restart tomcat
修改记录
2019-01-29 优化流程,并新增安装Jenkins细节
2018-09-04 新增该条目