jenkins

jenkins

1
2
3
https://gitee.com/tookoff/x-spring-boot.git

https://gitee.com/tookoff/x-spring-boot-ui.git
1
2
3
sh  'java --version'
sh 'git --version'
sh 'mvn --version'

密码

删除Jenkins目录下config.xml文件中下面代码

1
2
3
4
5
6
7
8
<useSecurity>true</useSecurity>  
<authorizationStrategy class="hudson.security.FullControlOnceLoggedInAuthorizationStrategy">
<denyAnonymousReadAccess>true</denyAnonymousReadAccess>
</authorizationStrategy>
<securityRealm class="hudson.security.HudsonPrivateSecurityRealm">
<disableSignup>true</disableSignup>
<enableCaptcha>false</enableCaptcha>
</securityRealm>

重新设密码

dae2b24cef9a4edd80fbd8453020062b

插件

https://www.cnblogs.com/zhoading/p/15085279.html

GitLab Hook

https://www.cnblogs.com/ygbh/p/17484753.html

docker-jenkins + gitlab/gogs仓库 + CD配置

https://blog.csdn.net/qq_38127559/article/details/130983686

SonarQube

SonarQube Scanner

SonarQube

  • 7.9之后的版本不在支持Mysql。使用PostgreSQL,SonarQube 9.9.5 LTA(2024.06)

PostgreSQL 15

1
2
3
4
5
6
postgres=# CREATE USER sonar WITH PASSWORD 'sonar123456';
CREATE ROLE
postgres=# CREATE DATABASE sonardb WITH OWNER sonar ENCODING UTF8;
CREATE DATABASE
postgres=# GRANT ALL PRIVILEGES ON DATABASE sonardb TO sonar;
GRANT
1
2
❯ psql -h 192.168.122.1 -U sonar -d sonardb -p 5433

在git根目录创建SonarQube配置文件
sonar-project.properties
sonar-project.properties
# must be unique in a given SonarQube instance
sonar.projectKey=web_demo_pipline
# this is the name and version displayed in the SonarQube UI. Was mandatory prior to SonarQube 6.1.
sonar.projectName=web_demo_pipline
sonar.projectVersion=1.0

# Path is relative to the sonar-project.properties file. Replace "\" by "/" on Windows. # sonar.sources:扫描的代码路径,下面代表所有代码 sonar.sources=. # 排除某些文件夹不扫描 sonar.exclusions=**/test/**,**/target/**
# JDK的版本 sonar.java.source=1.8 sonar.java.target=1.8
# 源码编码格式 # Encoding of the source code. Default is default system encoding sonar.sourceEncoding=UTF-8
pipeline
pipeline
pipeline {
   agent any

stages { stage('pull code') { steps { checkout([$class: 'GitSCM', branches: [[name: '*/${branch}']], doGenerateSubmoduleConfigurations: false, extensions: [], submoduleCfg: [], userRemoteConfigs: [[credentialsId: 'b632ed00-fc81-43c8-a746-5aa0673b2658', url: 'git@192.168.66.100:itheima_group/web_demo.git']]]) } } stage('code checking') { steps {
script { //引入SonarQubeScanner工具 scannerHome = tool 'sonar-scanner' } //引入SonarQube的服务器环境 withSonarQubeEnv('SonarQube-Server') { sh "${scannerHome}/bin/sonar-scanner" } } } stage('build project') { steps { sh 'mvn clean package' } } stage('publish project') { steps { deploy adapters: [tomcat8(credentialsId: 'fc23e5b7-9930-4dfb-af66-a2a576be52fb', path: '', url: 'http://192.168.66.102:8080')], contextPath: null, war: 'target/*.war' } } } post { always { emailext( subject: '构建通知:${PROJECT_NAME} - Build # ${BUILD_NUMBER} - ${BUILD_STATUS}!', body: '${FILE,path="email.html"}', to: 'xxxx@qq.com' ) } } }
令牌

squ_e0eaaff1e0143f550450760f0cf378c9b9004a89

ERROR

bootstrap check failure [1] of [1]: max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]

echo “vm.max_map_count = 262144” | sudo tee -a /etc/sysctl.conf

#生效

sysctl -p

other

execute shell

采取用execute shell启动/关闭tomcat,会发现可以进行关闭tomcat,但是无法启动tomcat,

BUILD_ID=DONTKILLME java -jar xxx.jar

修改/etc/sysconfig/jenkins配置

JENKINS_JAVA_OPTIONS中加入 -Dhudson.util.ProcessTree.disable=true

重启jenkins

jenkins执行服务器脚本失败

Publish Over SSH

jenkins 容器执行

1
ssh-keygen -t rsa

把生产 cat id_rsa.pub 内容追加到应用服务器 /root/.ssh/authorized_keys 里面

项目 Send build artifacts over SSH

node

代理端口设置

Dashboard > 系统管理 > 全局安全配置 > 代理

设置指定端口,并勾选代理协议

web启动

https://blog.csdn.net/wuxingge/article/details/117483179

ssh启动

https://cloud.tencent.com/developer/article/2028101

1
2
3
echo 88042b9d53210cab02deb5133f9635dd5adc2275c47bd702458887352bc033c0 > secret-file;
curl -sO http://localhost:8080/jnlpJars/agent.jar;
nohup java -jar agent.jar -url http://localhost:8080/ -secret @secret-file -name "node_py" -workDir "/home/cs/other/jenkins" > agent-node.log 2>&1 &

docker-inbound-agent

https://gitcode.com/jenkinsci/docker-inbound-agent/overview?utm_source=artical_gitcode

1
2
3
4
#docker run --init jenkins/inbound-agent -url http://jenkins-server:port -workDir=/home/jenkins/agent <secret> <agent name>

docker run --init k8s.org/cs/jenkins-inbound-agent:4.13.3-1 -url http://192.168.122.1:8080/ -workDir=/home/jenkins 81e2e0002a894e8b3b8952df455d7f23ced07e0694687fa56f750c541579102b docker_py --name jenkins_agent

记得替换 <secret><agent name> 为实际的密钥和代理名称

–network jenkins_default 同宿主机,不需要

1
2
docker  start  jenkins_agent
docker stop jenkins_agent

docker rm docker ps -a | grep jenkins-inbound-agent | awk '{print $1}'

pipline

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
pipeline {
agent {
// node { label "docker_py"}
node { label "node_py"}
}

stages {
stage('Hello') {
steps {
echo "$USER : $PWD"
echo 'Hello World'
}
}
}
}
点击打赏
文章目录
  1. 1. jenkins
    1. 1.1. 密码
  2. 2. 插件
    1. 2.0.1. GitLab Hook
  3. 2.1. SonarQube
    1. 2.1.1. SonarQube Scanner
    2. 2.1.2. SonarQube
      1. 2.1.2.1. 在git根目录创建SonarQube配置文件
      2. 2.1.2.2. 令牌
      3. 2.1.2.3. ERROR
  • 3. other
    1. 3.1. execute shell
    2. 3.2. Publish Over SSH
  • 4. node
    1. 4.1. web启动
    2. 4.2. ssh启动
    3. 4.3. docker-inbound-agent
  • 5. pipline
  • 载入天数...载入时分秒... ,