Jenkins使用备注
Jenkins 2.361.1(LTS)版本下载
官网下载地址:https://www.jenkins.io/download/
启动配置
1.配置JDK11
2.配置服务端口 --httpPort=9090
3.配置JENKINS_HOME,用于修改Jenkins存储与配置的目录
启动命令
重新设置Jenkins的存储与配置目录,set JENKINS_HOME=my-jenkins-config
java -jar jenkins.war [--httpPort=9090]
初始密码查看
cat /var/lib/jenkins/secrets/initialAdminPassword
如果在Docker中
docker exec ${CONTAINER_ID or CONTAINER_NAME} cat /var/jenkins_home/secrets/initialAdminPassword
Jenkins系统配置
Manage Jenkins->Configure System
通过全局属性,设置JAVA_HOME、M2_HOME、PATH+EXTRA
JAVA_HOME=/elk/app/java
M2_HOME=/opt/maven
PATH+EXTRA=$M2_HOME/bin
Jenkins插件安装
Manage Jenkins->插件管理->Available plugins
Git、GitLab、Localization(中文包)、Maven、NodeJS、NPM、SSH、Credentials(凭证管理)
升级站点设置
Manage Jenkins->插件管理->Advanced settings->升级站点
原地址:https://updates.jenkins.io/update-center.json
修改后地址:https://mirrors.tuna.tsinghua.edu.cn/jenkins/updates/update-center.json
Jenkins构建后执行脚本示例
rm -rf ./target mkdir -r docker/data/ROOT cd ./ && rm -rf ./target && mvn -s ./maven-settings.xml -B package -Dmaven.test.skip=true -Dautoconfig.skip branchName=$(echo $branch|awk -F'/' '{print $2}') echo "current branch is:"$branchName currentPath=`pwd` #jarName=`ls ./target/|grep \.jar$` jarName="project.war" if [ -z ./target/$jarName ];then echo "This package name is empty!" else dateStr=$(date +%Y_%m_%d_%H_%M_%S) \cp -rf ./target/$jarName ./docker/ cd docker rm -rf ./data/ROOT/* unzip $jarName -d ./data/ROOT imageName="registry.cn-hangzhou.aliyuncs.com/xxx/projectName:${branchName}_${dateStr}" docker build -t $imageName -f dockerfile.yml . docker push $imageName remoteIP="地址" USERNAME="root" PORT="22" ssh -p $PORT $USERNAME@$remoteIP "docker pull $imageName" ssh -p $PORT $USERNAME@$remoteIP "sed -i 's#\(image:\ \).*#\1${imageName}#' /etc/docker/package.yml" ssh -p $PORT $USERNAME@$remoteIP "docker service update --image $imageName projectStackName --with-registry-auth" fi