jdk 下載解壓 tar xzvf xxx.xxx maven 下載解壓 tar xzvf xxx.xxxjava
git 密鑰配置 ssh-keygen -t rsa -C "555555@qq.com" ssh git@192.168.1.5 git clone git@192.168.1.5:i/i.gitgit
2.2 啓動或中止 sudo service jenkins start/stop/restart sudo chkconfig jenkins ongithub
2.3 開啓防火牆端口 firewall-cmd --add-port=8080/tcp --permanent firewall-cmd --reload 默認端口爲8080,能夠在配置文件中修改 firewall-cmd --zone=public --add-port=8080/tcp --permanent systemctl restart firewalld //可能被佔用 kill -9 $(lsof -i tcp:8080 -t) //重啓 sudo service jenkins restart sudo chkconfig jenkins on http://192.168.1.5:8080 //密碼設爲 xxxxxx vim /etc/sysconfig/jenkins 8080端口多是git正在使用的端口 改爲8866
http://192.168.1.5:8866 firewall-cmd --zone=public --add-port=8866/tcp --permanent systemctl restart firewalldweb
3.3 配置環境變量 配置環境 vi /etc/profileredis
export JAVA_HOME=/xxx/xxx/jdk/jdk1.8.0 export JRE_HOME=${JAVA_HOME}/jre export CLASSPATH=.:${JAVA_HOME}/lib:${JRE_HOME}/libshell
export PATH=$JAVA_HOME/bin:$JAVA_HOME/jre/bin:$MAVEN_HOME/bin:$PATH:/usr/local/redis/bin:/usr/local/git/binapache
source /etc/profilevim
注意 maven無需配置 Please remove M2_HOME as environment variable, it is already set by the mvn script. The only things you need to do is: add apache-maven-3.x.x/bin to your path, set JAVA_HOME as environment variable. So no need to add %JAVA_HOME%/bin to your path export MAVEN_HOME=/usr/local/apache-mavenbash
Jenkins 經過shell腳本調用mvn 命令的時候,是從/usr/bin 文件夾中找命令的,這個時候須要作個軟連接服務器
ln –s /usr/local/apache-maven/bin/mvn /usr/bin/mvn
//在jenkins中配置 maven git jdk路徑 /usr/local/apache-maven /usr/local/git/bin /xxx/tool/jdk/jdk1.8.0_172
修改jenkins權限
chown -R root:root /var/lib/jenkins chown -R root:root /var/cache/jenkins chown -R root:root /var/log/jenkins 4).從新啓動Jenkins並檢查用戶是否已被更改
service jenkins restart
自動配置curl命令腳本 保存生sh 並執行
#!/bin/sh
tmp_dir='./tmp_install'
yum install -y pcre libxml2 git autoconf automake libtool perl*
if [ ! -d $tmp_dir ] then mkdir $tmp_dir fi
cd $tmp_dir
if [ ! -d 'curl' ] then git clone https://github.com/curl/curl.git fi
if [ find / -name libcurl.so | wc -l
-lt 1 ] then echo "try to install curl" cd curl ./buildconf ./configure make && make install cd .. echo "install curl finish" else echo "curl already install" fi
echo "all installed finish."
cd ..
//更新代碼 並maven install cd /home/tool/git/transcode/intellPrk git pull origin master
第一次運行: cd /home/tool/git/transcode/intellPrk/common-parent mvn clean install -Dmaven.test.skip=true
cd /root/.m2/repository/alipay/alipay-sdk-java/1.0 mvn install:install-file -DgroupId=alipay -DartifactId=alipay-sdk-java -Dversion=1.0 -Dpackaging=jar -Dfile=alipay-sdk-java-1.0.jar
mvn update
alipay\alipay-sdk-java\1.0 這邊的jar服務器可能下載不到 須要手動添加 目錄在/root/.m2/repository/alipay/alipay-sdk-java/1.0 先上傳alipay-sdk-java-1.0.jar 到home目錄 執行 上面語句後刪除
cd /xxx/git/transcode/xxx pwd mvn clean install -Dmaven.test.skip=true
後面直接: cd /xxx git pull origin master mvn clean install -Dmaven.test.skip=true
拷貝 #!/bin/bash work_path=/xxx/tool/git/transcode/xxx jar_path=/xxx/tool/git/transcode/jar cd $jar_path rm -rf $jar_path/basedata-service.jar cp $work_path/basedata-service/target/basedata-service.jar $jar_path/basedata-service.jar
若是報錯執行 yum install dos2unix dos2unix 腳本
cd /xxx/tool/git/transcode sh cpToJar.sh
以上方法jenkin沒法正常使用mvn命令
最後下載maven插件到jenkins 使用maven方式構建成功