yum install -y git
useradd git
passwd git
su - git
mkdir -p ~/repos/app.git
cd ~/repos/app.git
git --bare init
yum install -y git
cd /usr/local/src
git clone git@192.168.20.131:/home/git/repos/app.git
cd app
git config --global user.email "zhufengjiagou@126.com"
git config --global user.name "zhufengjiagou"
touch index.html
git add -A
git commit -m"init"
git push origin master
ssh-keygen -t rsa
cat ~/.ssh/id_rsa.pub
git
用户,就需要把自己的公钥拷贝到git
用户的authorized_keys
文件里ssh-keygen -t rsa
chmod 700 /home/git/.ssh
vi /home/git/.ssh/authorized_keys
chmod 600 /home/git/.ssh/authorized_keys
PubkeyAuthentication yes
systemctl restart sshd
cd /usr/local/src
wget http://upload-markdown-images.oss-cn-beijing.aliyuncs.com/jdk1.8.0_211.tar.gz
tar -xzvf jdk1.8.0_211.tar.gz
cp -r /usr/local/src/jdk1.8.0_211 /usr/java
rm -rf /usr/bin/java && ln -s /usr/java/jdk1.8.0_211/bin/java /usr/bin/java
vi /etc/profile
JAVA_HOME=/usr/java/jdk1.8.0_211
export CLASSPATH=.:${JAVA_HOME}/jre/lib/rt.jar:${JAVA_HOME}/lib/dt.jar:${JAVA_HOME}/lib/tools.jar
export PATH=$PATH:${JAVA_HOME}/bin
source /etc/profile
java --version
wget -O /etc/yum.repos.d/jenkins.repo https://pkg.jenkins.io/redhat-stable/jenkins.repo
rpm --import https://pkg.jenkins.io/redhat-stable/jenkins.io.key
yum install -y jenkins
systemctl stop firewalld.service
systemctl disable firewalld.service
javap -v JNLPMain.class
J2SE 8 = 52
J2SE 7 = 51
J2SE 6.0 = 50
J2SE 5.0 = 49
JDK 1.4 = 48
JDK 1.3 = 47
JDK 1.2 = 46
JDK 1.1 = 45
systemctl start jenkins
systemctl daemon-reload
systemctl status jenkins
vi /etc/init.d/jenkins
candidates="
#/etc/alternatives/java
#/usr/lib/jvm/java-1.8.0/bin/java
#/usr/lib/jvm/jre-1.8.0/bin/java
#/usr/lib/jvm/java-1.7.0/bin/java
#/usr/lib/jvm/jre-1.7.0/bin/java
/usr/bin/java
"
一定要改一下root用户,不然流水线SCM拉不到脚本 vi /etc/sysconfig/jenkins
JENKINS_USER="root"
yum install maven -y
# rpm -ql maven
/etc/m2.conf
/etc/maven
/etc/maven/settings.xml
/usr/bin/mvn
/usr/share/maven/conf/settings.xml
插件名称 | 插件作用 |
---|---|
Folders | (https://plugins.jenkins.io/cloudbees-folder),这个插件支持用户使用目录管理项目,目录支持嵌套,并且支持目录中创建视图 |
OWASP Markup Formatter | OWASP标记格式化程序插件,使用OWASP Java HTML Sanitizer ,可以在项目描述等中输入安全的HTML标记 |
Build Timeout | 构建超时,此插件允许构建在指定的时间过后自动终止 |
Credentials Binding | 证书绑定 |
Timestamper | 将时间戳添加到控制台输出 |
Workspace Cleanup | (https://plugins.jenkins.io/ws-cleanup),这个插件支持在构建前后 删除或者部分删除workspace |
Ant | 向Jenkins添加Apache Ant支持 |
Gradle | 这个插件允许Jenkins直接调用Gradle构建脚本 |
Pipeline | 管道,一套插件可让您协调自动化 |
Pipeline: GitHub Groovy Libraries | 允许从GitHub动态加载Pipeline Groovy库 |
Pipeline: Stage View | 查看每一步的执行结果 |
GitHub Branch Source | GitHub组织文件夹插件 |
Git | (https://plugins.jenkins.io/git),支持使用Github、GitLab、Gerrit等系统管理代码仓库 |
Subversion | (https://plugins.jenkins.io/subversion),支持Subversion系统管理源代码 |
SSH Slaves | SSH登录到一个远程服务器以执行必要的脚本 |
Matrix Authorization Strategy | 矩阵授权策略插件,提供基于矩阵的安全授权策略(全局和每个项目) |
PAM Authentication | 为Jenkins添加Unix可插入身份验证模块(PAM)支持 |
LDAP | (https://plugins.jenkins.io/ldap),这个插件允许使用LDAP对用户进行认证,LDAP 服务器可以为Active Directory 或者 OpenLDAP |
Email Extension | 这个插件是Jenkins的电子邮件发布者的替代品。它允许配置电子邮件通知的各个方面:发送电子邮件时,应该收到谁以及电子邮件说明的内容 |
Mailer | 发邮件服务 |
Localization: Chinese (Simplified) | 本地化构建 |
vi /etc/sysconfig/jenkins 一定要改一下root用户,不然流水线SCM拉不到脚本
JENKINS_USER="root"
git branch test
git checkout test
git branch
touch 5.txt
git add -A
git commit -m"add 5.txt"
git git push origin test
git push origin test
node {
stage ('checkout'){
echo "checkout"
}
stage ('build'){
echo "build"
}
stage ('deploy'){
echo "deploy"
}
stage ('test'){
echo "test"
}
}
node('slave') {
stage ('checkout'){
echo "checkout2"
sleep time: 10, unit: 'SECONDS'
}
stage ('build'){
echo "build"
}
stage ('deploy'){
echo "deploy"
}
stage ('test'){
echo "test"
}
}
mkdir -p /home/git/repos/dev-php.git
cd /home/git/repos/dev-php.git
git init --bare
git clone git@192.168.20.131:/home/git/repos/dev-php.git
cd php
echo "<?php echo info()?>" > index.php
git add -A
git commit -m"add index.php"
git push origin master
dev-php
项目给web服务器添加标签名并在pipeline脚本中引用
web服务器上的工作目录 /var/lib/jenkins/workspace/dev-php
cat /root/pipeline/Jenkinsfile-php
node('webserver') {
stage ('checkout'){
checkout([$class: 'GitSCM', branches: [[name: '*/master']], doGenerateSubmoduleConfigurations: false, extensions: [], submoduleCfg: [], userRemoteConfigs: [[credentialsId: '8e8e63f9-4806-4f2e-8633-c92badbdefd7', url: "git@192.168.20.131:/home/git/repos/${JOB_NAME}.git"]]])
}
stage ('build'){
sh '''rm -rf ${WORKSPACE}/.git
[ -e /data/backup ] || mkdir -p /data/backup
[ -e /usr/share/nginx/html/${JOB_NAME} ] || mkdir /usr/share/nginx/html/${JOB_NAME}
mv /usr/share/nginx/html/${JOB_NAME} /data/backup/${JOB_NAME}"-$(date +%F_%T)"
cp -rf ${WORKSPACE} /usr/share/nginx/html'''
}
stage ('test'){
sh "curl http://www.${JOB_NAME}.com/status"
}
}
mkdir -p /home/git/repos/dev-java.git
cd /home/git/repos/dev-java.git
git init --bare
git clone git@github.com:zhufengnodejs/blog2.git
git clone git@192.168.20.131:/home/git/repos/dev-java.git
git add -A && git commit -m"blog2" && git push origin master
node ("webserver") {
stage('git checkout') {
checkout([$class: 'GitSCM', branches: [[name: '*/master']], doGenerateSubmoduleConfigurations: false, extensions: [], submoduleCfg: [], userRemoteConfigs: [[credentialsId: '8e8e63f9-4806-4f2e-8633-c92badbdefd7', url: "git@192.168.20.131:/home/git/repos/${JOB_NAME}.git"]]])
}
stage('maven build') {
sh '''export JAVA_HOME=/usr/java/jdk1.8.0_211
/usr/bin/mvn clean package'''
}
stage('deploy') {
sh '''
JENKINS_NODE_COOKIE=dontkillme
export JAVA_HOME=/usr/java/jdk1.8.0_211
TOMCAT_NAME=tomcat
TOMCAT_HOME=/usr/local/$TOMCAT_NAME
WWWROOT=$TOMCAT_HOME/webapps/ROOT
if [ -d $WWWROOT ]; then
mv $WWWROOT /data/backup/${TOMCAT_NAME}-$(date +"%F_%T")
fi
unzip ${WORKSPACE}/target/*.war -d $WWWROOT
PID=$(ps -ef |grep $TOMCAT_NAME |egrep -v "grep|$$" |awk '{print $2}')
[ -n "$PID" ] && kill -9 $PID
/bin/bash $TOMCAT_HOME/bin/startup.sh'''
}
stage('test') {
sh "curl http://www.de-java.com/status.html"
}
}
node ("webserver") {
stage('Git Checkout') {
checkout([$class: 'GitSCM', branches: [[name: '$Tag']], doGenerateSubmoduleConfigurations: false, extensions: [], submoduleCfg: [], userRemoteConfigs: [[url: 'git@192.168.0.219:/home/git/solo.git']]])
}
stage('Maven Build') {
sh '''
export JAVA_HOME=/usr/local/jdk1.8
/usr/local/maven3.5/bin/mvn clean package -Dmaven.test.skip=true
'''
}
stage('Build and Push Image') {
sh '''
REPOSITORY=192.168.0.2/project/dev-docker:${Tag}
cat > Dockerfile << EOF
FROM 192.168.0.2/library/tomcat-85:latest
RUN rm -rf /usr/local/tomcat/webapps/ROOT
COPY target/*.war /usr/local/tomcat/webapps/ROOT.war
CMD ["catalina.sh", "run"]
EOF
docker build -t $REPOSITORY .
docker login -u zhangrenyang -p xxx= 192.168.0.2
docker push $REPOSITORY
'''
}
stage('Deploy to Docker') {
sh '''
REPOSITORY=192.168.0.219/project/dev-docker:${Tag}
docker rm -f dev-docker: |true
docker image rm $REPOSITORY |true
docker login -u zhangrenyang -p xxx= 192.168.0.2
docker container run -d --name dev-docker -v /usr/local/jdk1.8:/usr/local/jdk -p 88:8080 $REPOSITORY
'''
}
}