栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 系统运维 > 运维 > Linux

服务器搭建系列之9:k8s安装jenkins实现自动化部署(包含全流程配置),2022最新版本

Linux 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

服务器搭建系列之9:k8s安装jenkins实现自动化部署(包含全流程配置),2022最新版本

准备工作:
下载jenkins安装包,地址:jenkins的rpm安装包
下载maven安装包,地址:maven下载地址
下载jdk8和jdk17的tar包,地址:jdk下载地址
下载publish-over-ssh安装包,地址:插件下载

将下方内容保存为对应名称文件

vim jenkins

## Path:        Development/Jenkins
## Description: Jenkins Automation Server
## Type:        string
## Default:     "/var/lib/jenkins"
## ServiceRestart: jenkins
#
# Directory where Jenkins store its configuration and working
# files (checkouts, build reports, artifacts, ...).
#
JENKINS_HOME="/var/lib/jenkins"

## Type:        string
## Default:     ""
## ServiceRestart: jenkins
#
# Java executable to run Jenkins
# When left empty, we'll try to find the suitable Java.
#
JENKINS_JAVA_CMD=""

## Type:        string
## Default:     "jenkins"
## ServiceRestart: jenkins
#
# Unix user account that runs the Jenkins daemon
# Be careful when you change this, as you need to update
# permissions of $JENKINS_HOME and /var/log/jenkins.
#
JENKINS_USER="root"

## Type:        string
## Default: "false"
## ServiceRestart: jenkins
#
# Whether to skip potentially long-running chown at the
# $JENKINS_HOME location. Do not enable this, "true", unless
# you know what you're doing. See JENKINS-23273.
#
#JENKINS_INSTALL_SKIP_CHOWN="false"

## Type: string
## Default:     "-Djava.awt.headless=true"
## ServiceRestart: jenkins
#
# Options to pass to java when running Jenkins.
#
JENKINS_JAVA_OPTIONS="-Djava.awt.headless=true"

## Type:        integer(0:65535)
## Default:     8080
## ServiceRestart: jenkins
#
# Port Jenkins is listening on.
# Set to -1 to disable
#
JENKINS_PORT="8080"

## Type:        string
## Default:     ""
## ServiceRestart: jenkins
#
# IP address Jenkins listens on for HTTP requests.
# Default is all interfaces (0.0.0.0).
#
JENKINS_LISTEN_ADDRESS=""

## Type:        integer(0:65535)
## Default:     ""
## ServiceRestart: jenkins
#
# HTTPS port Jenkins is listening on.
# Default is disabled.
#
JENKINS_HTTPS_PORT=""

## Type:        string
## Default:     ""
## ServiceRestart: jenkins
#
# Path to the keystore in JKS format (as created by the JDK 'keytool').
# Default is disabled.
#
JENKINS_HTTPS_KEYSTORE=""

## Type:        string
## Default:     ""
## ServiceRestart: jenkins
#
# Password to access the keystore defined in JENKINS_HTTPS_KEYSTORE.
# Default is disabled.
#
JENKINS_HTTPS_KEYSTORE_PASSWORD=""

## Type:        string
## Default:     ""
## ServiceRestart: jenkins
#
# IP address Jenkins listens on for HTTPS requests.
# Default is disabled.
#
JENKINS_HTTPS_LISTEN_ADDRESS=""

## Type:        integer(0:65535)
## Default:     ""
## ServiceRestart: jenkins
#
# HTTP2 port Jenkins is listening on.
# Default is disabled.
#
# Notice: HTTP2 support may require additional configuration, see Winstone
# documentation for more information.
#
JENKINS_HTTP2_PORT=""

## Type:        string
## Default:     ""
## ServiceRestart: jenkins
#
# IP address Jenkins listens on for HTTP2 requests.
# Default is disabled.
#
# Notice: HTTP2 support may require additional configuration, see Winstone
# documentation for more information.
#
JENKINS_HTTP2_LISTEN_ADDRESS=""

## Type:        integer(1:9)
## Default:     5
## ServiceRestart: jenkins
#
# Debug level for logs -- the higher the value, the more verbose.
# 5 is INFO.
#
JENKINS_DEBUG_LEVEL="5"

## Type:        yesno
## Default:     no
## ServiceRestart: jenkins
#
# Whether to enable access logging or not.
#
JENKINS_ENABLE_ACCESS_LOG="no"

## Type:        integer
## Default:     100
## ServiceRestart: jenkins
#
# Maximum number of HTTP worker threads.
#
JENKINS_HANDLER_MAX="100"

## Type:        integer
## Default:     20
## ServiceRestart: jenkins
#
# Maximum number of idle HTTP worker threads.
#
JENKINS_HANDLER_IDLE="20"

## Type:        string
## Default:     ""
## ServiceRestart: jenkins
#
# Folder for additional jar files to add to the Jetty class loader.
# See Winstone documentation for more information.
# Default is disabled.
#
JENKINS_EXTRA_LIB_FOLDER=""

## Type:        string
## Default:     ""
## ServiceRestart: jenkins
#
# Pass arbitrary arguments to Jenkins.
# Full option list: java -jar jenkins.war --help
#
JENKINS_ARGS=""

vim mvn8

#!/bin/sh
JAVA_HOME=/home/jdk8
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements.  See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership.  The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License.  You may obtain a copy of the License at
#
#    http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR ConDITIONS OF ANY
# KIND, either express or implied.  See the License for the
# specific language governing permissions and limitations
# under the License.

# -----------------------------------------------------------------------------
# Apache Maven Startup script
#
# Environment Variable Prerequisites
#
#   JAVA_HOME       Must point at your Java Development Kit installation.
#   MAVEN_OPTS      (Optional) Java runtime options used when Maven is executed.
#   MAVEN_SKIP_RC   (Optional) Flag to disable loading of mavenrc files.
# -----------------------------------------------------------------------------

if [ -z "$MAVEN_SKIP_RC" ] ; then

  if [ -f /usr/local/etc/mavenrc ] ; then
    . /usr/local/etc/mavenrc
  fi

  if [ -f /etc/mavenrc ] ; then
    . /etc/mavenrc
  fi

  if [ -f "$HOME/.mavenrc" ] ; then
    . "$HOME/.mavenrc"
  fi

fi

# OS specific support. $var _must_ be set to either true or false.
cygwin=false;
mingw=false;
case "`uname`" in
  CYGWIN*) cygwin=true;;
  MINGW*) mingw=true;;
esac

## resolve links - $0 may be a link to Maven's home
PRG="$0"

# need this for relative symlinks
while [ -h "$PRG" ] ; do
  ls=`ls -ld "$PRG"`
  link=`expr "$ls" : '.*-> (.*)$'`
  if expr "$link" : '/.*' > /dev/null; then
    PRG="$link"
  else
    PRG="`dirname "$PRG"`/$link"
  fi
done

saveddir=`pwd`

MAVEN_HOME=`dirname "$PRG"`/..

# make it fully qualified
MAVEN_HOME=`cd "$MAVEN_HOME" && pwd`

cd "$saveddir"

# For Cygwin, ensure paths are in Unix format before anything is touched
if $cygwin ; then
  [ -n "$MAVEN_HOME" ] &&
    MAVEN_HOME=`cygpath --unix "$MAVEN_HOME"`
  [ -n "$JAVA_HOME" ] &&
    JAVA_HOME=`cygpath --unix "$JAVA_HOME"`
  [ -n "$CLASSPATH" ] &&
    CLASSPATH=`cygpath --path --unix "$CLASSPATH"`
fi

# For MinGW, ensure paths are in Unix format before anything is touched
if $mingw ; then
  [ -n "$MAVEN_HOME" ] &&
    MAVEN_HOME=`(cd "$MAVEN_HOME"; pwd)`
  [ -n "$JAVA_HOME" ] &&
    JAVA_HOME=`(cd "$JAVA_HOME"; pwd)`
  # TODO classpath?
fi

if [ -z "$JAVA_HOME" ] ; then
  JAVACMD="`\unset -f command; \command -v java`"
else
  JAVACMD="$JAVA_HOME/bin/java"
fi

if [ ! -x "$JAVACMD" ] ; then
  echo "The JAVA_HOME environment variable is not defined correctly," >&2
  echo "this environment variable is needed to run this program." >&2
  exit 1
fi

CLASSWORLDS_JAR=`echo "${MAVEN_HOME}"/boot/plexus-classworlds-*.jar`
CLASSWORLDS_LAUNCHER=org.codehaus.plexus.classworlds.launcher.Launcher

# For Cygwin, switch paths to Windows format before running java
if $cygwin ; then
  [ -n "$MAVEN_HOME" ] &&
    MAVEN_HOME=`cygpath --path --windows "$MAVEN_HOME"`
  [ -n "$JAVA_HOME" ] &&
    JAVA_HOME=`cygpath --path --windows "$JAVA_HOME"`
  [ -n "$CLASSPATH" ] &&
    CLASSPATH=`cygpath --path --windows "$CLASSPATH"`
  [ -n "$CLASSWORLDS_JAR" ] &&
    CLASSWORLDS_JAR=`cygpath --path --windows "$CLASSWORLDS_JAR"`
fi

# traverses directory structure from process work directory to filesystem root
# first directory with .mvn subdirectory is considered project base directory
find_maven_basedir() {
(
  basedir=`find_file_argument_basedir "$@"`
  wdir="${basedir}"
  while [ "$wdir" != '/' ] ; do
    if [ -d "$wdir"/.mvn ] ; then
      basedir=$wdir
      break
    fi
    wdir=`cd "$wdir/.."; pwd`
  done
  echo "${basedir}"
)
}

find_file_argument_basedir() {
(
  basedir=`pwd`

  found_file_switch=0
  for arg in "$@"; do
    if [ ${found_file_switch} -eq 1 ]; then
      if [ -d "${arg}" ]; then
        basedir=`cd "${arg}" && pwd -P`
      elif [ -f "${arg}" ]; then
        basedir=`dirname "${arg}"`
        basedir=`cd "${basedir}" && pwd -P`
        if [ ! -d "${basedir}" ]; then
          echo "Directory ${basedir} extracted from the -f/--file command-line argument ${arg} does not exist" >&2
          exit 1
        fi
      else
        echo "POM file ${arg} specified with the -f/--file command line argument does not exist" >&2
        exit 1
      fi
      break
    fi
    if [ "$arg" = "-f" -o "$arg" = "--file" ]; then
      found_file_switch=1
    fi
  done
  echo "${basedir}"
)
}

# concatenates all lines of a file
concat_lines() {
  if [ -f "$1" ]; then
    echo "`tr -s 'rn' '  ' < "$1"`"
  fi
}

MAVEN_PROJECTbaseDIR="${MAVEN_baseDIR:-`find_maven_basedir "$@"`}"
MAVEN_OPTS="`concat_lines "$MAVEN_PROJECTbaseDIR/.mvn/jvm.config"` $MAVEN_OPTS"

# For Cygwin, switch project base directory path to Windows format before
# executing Maven otherwise this will cause Maven not to consider it.
if $cygwin ; then
  [ -n "$MAVEN_PROJECTbaseDIR" ] &&
  MAVEN_PROJECTbaseDIR=`cygpath --path --windows "$MAVEN_PROJECTbaseDIR"`
fi

export MAVEN_PROJECTbaseDIR

# Provide a "standardized" way to retrieve the CLI args that will
# work with both Windows and non-Windows executions.
MAVEN_CMD_LINE_ARGS="$MAVEN_CONFIG $@"
export MAVEN_CMD_LINE_ARGS

exec "$JAVACMD" 
  $MAVEN_OPTS 
  $MAVEN_DEBUG_OPTS 
  -classpath "${CLASSWORLDS_JAR}" 
  "-Dclassworlds.conf=${MAVEN_HOME}/bin/m2.conf" 
  "-Dmaven.home=${MAVEN_HOME}" 
  "-Dlibrary.jansi.path=${MAVEN_HOME}/lib/jansi-native" 
  "-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTbaseDIR}" 
  ${CLASSWORLDS_LAUNCHER} "$@"

vim mvn17

#!/bin/sh
JAVA_HOME=/home/jdk17
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements.  See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership.  The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License.  You may obtain a copy of the License at
#
#    http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR ConDITIONS OF ANY
# KIND, either express or implied.  See the License for the
# specific language governing permissions and limitations
# under the License.

# -----------------------------------------------------------------------------
# Apache Maven Startup script
#
# Environment Variable Prerequisites
#
#   JAVA_HOME       Must point at your Java Development Kit installation.
#   MAVEN_OPTS      (Optional) Java runtime options used when Maven is executed.
#   MAVEN_SKIP_RC   (Optional) Flag to disable loading of mavenrc files.
# -----------------------------------------------------------------------------

if [ -z "$MAVEN_SKIP_RC" ] ; then

  if [ -f /usr/local/etc/mavenrc ] ; then
    . /usr/local/etc/mavenrc
  fi

  if [ -f /etc/mavenrc ] ; then
    . /etc/mavenrc
  fi

  if [ -f "$HOME/.mavenrc" ] ; then
    . "$HOME/.mavenrc"
  fi

fi

# OS specific support. $var _must_ be set to either true or false.
cygwin=false;
mingw=false;
case "`uname`" in
  CYGWIN*) cygwin=true;;
  MINGW*) mingw=true;;
esac

## resolve links - $0 may be a link to Maven's home
PRG="$0"

# need this for relative symlinks
while [ -h "$PRG" ] ; do
  ls=`ls -ld "$PRG"`
  link=`expr "$ls" : '.*-> (.*)$'`
  if expr "$link" : '/.*' > /dev/null; then
    PRG="$link"
  else
    PRG="`dirname "$PRG"`/$link"
  fi
done

saveddir=`pwd`

MAVEN_HOME=`dirname "$PRG"`/..

# make it fully qualified
MAVEN_HOME=`cd "$MAVEN_HOME" && pwd`

cd "$saveddir"

# For Cygwin, ensure paths are in Unix format before anything is touched
if $cygwin ; then
  [ -n "$MAVEN_HOME" ] &&
    MAVEN_HOME=`cygpath --unix "$MAVEN_HOME"`
  [ -n "$JAVA_HOME" ] &&
    JAVA_HOME=`cygpath --unix "$JAVA_HOME"`
  [ -n "$CLASSPATH" ] &&
    CLASSPATH=`cygpath --path --unix "$CLASSPATH"`
fi

# For MinGW, ensure paths are in Unix format before anything is touched
if $mingw ; then
  [ -n "$MAVEN_HOME" ] &&
    MAVEN_HOME=`(cd "$MAVEN_HOME"; pwd)`
  [ -n "$JAVA_HOME" ] &&
    JAVA_HOME=`(cd "$JAVA_HOME"; pwd)`
  # TODO classpath?
fi

if [ -z "$JAVA_HOME" ] ; then
  JAVACMD="`\unset -f command; \command -v java`"
else
  JAVACMD="$JAVA_HOME/bin/java"
fi

if [ ! -x "$JAVACMD" ] ; then
  echo "The JAVA_HOME environment variable is not defined correctly," >&2
  echo "this environment variable is needed to run this program." >&2
  exit 1
fi

CLASSWORLDS_JAR=`echo "${MAVEN_HOME}"/boot/plexus-classworlds-*.jar`
CLASSWORLDS_LAUNCHER=org.codehaus.plexus.classworlds.launcher.Launcher

# For Cygwin, switch paths to Windows format before running java
if $cygwin ; then
  [ -n "$MAVEN_HOME" ] &&
    MAVEN_HOME=`cygpath --path --windows "$MAVEN_HOME"`
  [ -n "$JAVA_HOME" ] &&
    JAVA_HOME=`cygpath --path --windows "$JAVA_HOME"`
  [ -n "$CLASSPATH" ] &&
    CLASSPATH=`cygpath --path --windows "$CLASSPATH"`
  [ -n "$CLASSWORLDS_JAR" ] &&
    CLASSWORLDS_JAR=`cygpath --path --windows "$CLASSWORLDS_JAR"`
fi

# traverses directory structure from process work directory to filesystem root
# first directory with .mvn subdirectory is considered project base directory
find_maven_basedir() {
(
  basedir=`find_file_argument_basedir "$@"`
  wdir="${basedir}"
  while [ "$wdir" != '/' ] ; do
    if [ -d "$wdir"/.mvn ] ; then
      basedir=$wdir
      break
    fi
    wdir=`cd "$wdir/.."; pwd`
  done
  echo "${basedir}"
)
}

find_file_argument_basedir() {
(
  basedir=`pwd`

  found_file_switch=0
  for arg in "$@"; do
    if [ ${found_file_switch} -eq 1 ]; then
      if [ -d "${arg}" ]; then
        basedir=`cd "${arg}" && pwd -P`
      elif [ -f "${arg}" ]; then
        basedir=`dirname "${arg}"`
        basedir=`cd "${basedir}" && pwd -P`
        if [ ! -d "${basedir}" ]; then
          echo "Directory ${basedir} extracted from the -f/--file command-line argument ${arg} does not exist" >&2
          exit 1
        fi
      else
        echo "POM file ${arg} specified with the -f/--file command line argument does not exist" >&2
        exit 1
      fi
      break
    fi
    if [ "$arg" = "-f" -o "$arg" = "--file" ]; then
      found_file_switch=1
    fi
  done
  echo "${basedir}"
)
}

# concatenates all lines of a file
concat_lines() {
  if [ -f "$1" ]; then
    echo "`tr -s 'rn' '  ' < "$1"`"
  fi
}

MAVEN_PROJECTbaseDIR="${MAVEN_baseDIR:-`find_maven_basedir "$@"`}"
MAVEN_OPTS="`concat_lines "$MAVEN_PROJECTbaseDIR/.mvn/jvm.config"` $MAVEN_OPTS"

# For Cygwin, switch project base directory path to Windows format before
# executing Maven otherwise this will cause Maven not to consider it.
if $cygwin ; then
  [ -n "$MAVEN_PROJECTbaseDIR" ] &&
  MAVEN_PROJECTbaseDIR=`cygpath --path --windows "$MAVEN_PROJECTbaseDIR"`
fi

export MAVEN_PROJECTbaseDIR

# Provide a "standardized" way to retrieve the CLI args that will
# work with both Windows and non-Windows executions.
MAVEN_CMD_LINE_ARGS="$MAVEN_CONFIG $@"
export MAVEN_CMD_LINE_ARGS

exec "$JAVACMD" 
  $MAVEN_OPTS 
  $MAVEN_DEBUG_OPTS 
  -classpath "${CLASSWORLDS_JAR}" 
  "-Dclassworlds.conf=${MAVEN_HOME}/bin/m2.conf" 
  "-Dmaven.home=${MAVEN_HOME}" 
  "-Dlibrary.jansi.path=${MAVEN_HOME}/lib/jansi-native" 
  "-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTbaseDIR}" 
  ${CLASSWORLDS_LAUNCHER} "$@"

vim settings.xml
可自行配置server,mirrors,docker镜像仓库账号密码等





    /home/repository

    
    

    
    

    
        
            releases
            admin
            123456
        
        
            snapshots
            admin
            123456
        
        
            docker-aliyun
            阿里云账号
            阿里云密码
        
    

    
        
            alimaven
            central
            http://maven.aliyun.com/nexus/content/groups/public
        
    

    
    

    
    



Dockerfile

需要用到jdk11基础镜像
强烈建议使用本人构建的镜像,否则jenkins构建步骤不支持中文
将下方安装包名称修改为下载的安装包名称

FROM registry.cn-qingdao.aliyuncs.com/fandai/fd-jdk11
COPY jenkins-2.332-1.1.noarch.rpm /home/jenkins-2.332-1.1.noarch.rpm
COPY apache-maven-3.8.4-bin.tar.gz /home/apache-maven-3.8.4-bin.tar.gz
COPY jdk-8u321-linux-x64.tar.gz /home/jdk-8u321-linux-x64.tar.gz
COPY jdk-17_linux-x64_bin.tar.gz /home/jdk-17_linux-x64_bin.tar.gz

WORKDIR /home/

RUN tar -zxvf apache-maven-3.8.4-bin.tar.gz && 
    tar -zxvf jdk-8u321-linux-x64.tar.gz && 
    tar -zxvf jdk-17_linux-x64_bin.tar.gz && 
    mv jdk1.8.0_321 jdk8 && 
    mv jdk-17.0.2 jdk17 && 
    mv apache-maven-3.8.4 maven && 
    yum -y install epel-release && 
    yum -y install daemonize initscripts git && 
    rpm -ivh jenkins-2.332-1.1.noarch.rpm && 
    rm -rf jenkins-2.332-1.1.noarch.rpm && 
    rm -rf apache-maven-3.8.4-bin.tar.gz && 
    rm -rf jdk-8u321-linux-x64.tar.gz && 
    rm -rf jdk-17_linux-x64_bin.tar.gz && 
    echo "export MAVEN_HOME=/home/maven" >> /etc/profile && 
    echo -e "PATH=$PATH:$JAVA_HOME/bin:$MAVEN_HOME/bin" >> /etc/profile && 
    source /etc/profile

COPY settings.xml /home/maven/conf/settings.xml
COPY mvn8 /home/maven/bin/mvn8
COPY mvn17 /home/maven/bin/mvn17

COPY jenkins /var/sysconfig/jenkins

#赋予执行权限,修改编码格式
RUN chmod +x /home/maven/bin/mvn8 && sed -i "s/r//" mvn8
RUN chmod +x /home/maven/bin/mvn17 && sed -i "s/r//" mvn17
RUN ln -s /home/maven/bin/mvn /usr/local/bin/
RUN ln -s /home/maven/bin/mvn8 /usr/local/bin/
RUN ln -s /home/maven/bin/mvn17 /usr/local/bin/

EXPOSE 8080
EXPOSE 50000
deoply.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  name: jenkins
  namespace: fandai
spec:
  replicas: 1
  selector:
    matchLabels:
      app: jenkins
  template:
    metadata:
      labels:
        app: jenkins
    spec:
      containers:
        - name: jenkins
          image: registry.cn-qingdao.aliyuncs.com/fandai/jenkins  # 可使用本人生成的镜像,或通过dockerfile自行构建
          command: ["java","-jar","/usr/lib/jenkins/jenkins.war"]
          env:
            - name: USER_UID
              value: "1000"
            - name: USER_GID
              value: "1000"
          volumeMounts:
            - name: jenkins
              mountPath: /root/.jenkins
      volumes:
        - name: jenkins
          nfs:
            server: fandai-nfs  #nfs服务器地址
            path: /home/nfs/jenkins #共享文件路径
---
apiVersion: v1  # 资源版本
kind: Service  # 资源类型
metadata: # 元数据
  name: jenkins # 资源名称
  namespace: fandai # 命名空间
spec: # 描述
  selector: # 标签选择器,用于确定当前service代理哪些pod
    app: jenkins
  type: NodePort # service类型
  ports: # 端口信息
    - protocol: TCP
      name: jenkins1
      port: 8080  # service端口
      targetPort: 8080 # pod端口
    - protocol: TCP
      name: jenkins2
      port: 50000  # service端口
      targetPort: 50000 # pod端口
    - protocol: TCP
      name: jenkins3
      port: 38742  # service端口
      targetPort: 38742 # pod端口
kubectl apply -f deploy.yaml
修改jenkins插件仓库地址
https://mirrors.tuna.tsinghua.edu.cn/jenkins/updates/update-center.json
jenkins配置中文界面

下载插件Locale和chinese
配置中修改Locale为zh_cn

maven和jdk配置


配置webhook

下载插件
下方以gitea私有git仓库为例,github、gitee等类似,gitea安装请参考本人其他教程


配置token


构建完成发送邮件

安装插件


邮件模板:email.html




    
    ${ENV, var="JOB_NAME"}-第${BUILD_NUMBER}次构建日志



(本邮件是Jenkins程序自动下发的,请勿回复!)
构建结果 - ${BUILD_STATUS}

构建信息:

项目名称:${PROJECT_NAME} 构建编号:第${BUILD_NUMBER}次构建 触发原因:${CAUSE} 构建日志:"${BUILD_URL}console">${BUILD_URL}console 构建地址:"${BUILD_URL}">${BUILD_URL} 工作目录:"${PROJECT_URL}ws">${PROJECT_URL}ws 项目地址:"${PROJECT_URL}">${PROJECT_URL} 变更集:${JELLY_script,template="html"}

Changes Since Last Successful Build:

历史变更记录 : "${PROJECT_URL}changes">${PROJECT_URL}changes ${CHANGES_SINCE_LAST_SUCCESS,reverse=true, format="Changes for Build #%n:
%c
",showPaths=true,changesFormat="

[%a]
%m
",pathFormat="%p"}
Failed Test Results:
${FAILED_TESTS}

构建日志 (最后 100行):
Test Logs (if test has ran): "${PROJECT_URL}ws/TestResult/archive_logs/Log-Build-${BUILD_NUMBER}.zip">${PROJECT_URL}/ws/TestResult/archive_logs/Log-Build-${BUILD_NUMBER}.zip

jenkinsfile中添加配置

post{
    always{
    	emailext body: '${FILE,path="email.html"}', subject: '构建通知:${PROJECT_NAME} - Build # ${BUILD_NUMBER} - ${BUILD_STATUS}!', to: '******@163.com'
    }
}
sonarqube代码审查

sonarqube服务端搭建请参考:服务器搭建系列之8:k8s安装sonarQube代码审查工具,2022最新版本

下载插件


publish over ssh

jenkins容器运行,生成秘钥,要求是旧版

ssh-keygen -m PEM -t rsa -b 4096

将/root/.ssh/id_rsa拷贝到要访问的机器的/root/.ssh/authorized_keys

构建多选框

下载插件

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/733407.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号