• Gitlab_ansible_jenkins三剑客④jenkins安装图解及freestyle的简单使用


    java环境准备

    # 安装jdk1.8

    [root@node02 ~]# rpm -ivh jdk-8u181-linux-x64.rpm

    vim /etc/profile

    export JAVA_HOME=/usr/java/jdk1.8.0_181-amd64

    export PATH=$JAVA_HOME/bin:$PATH

    # 验证是否安装成功

    [root@node02 ~]# java -version

    java version "1.8.0_181"

    Java(TM) SE Runtime Environment (build 1.8.0_181-b13)

    Java HotSpot(TM) 64-Bit Server VM (build 25.181-b13, mixed mode)

    方法1:安装jar包形式的jenkins(不推荐)

    jenkins相关的yum环境准备

    [root@node02 ~]# wget -O /etc/yum.repos.d/jenkins.repo http://pkg.jenkins.io/redhat-stable/jenkins.repo

    export http_proxy=http://10.11.0.148:808

    export https_proxy=http://10.11.0.148:808

    export ftp_proxy=http://10.11.0.148:808

    [root@node02 ~]# rpm --import https://pkg.jenkins.io/redhat-stable/jenkins.io.key

    # 下载jenkins并安装

    https://prodjenkinsreleases.blob.core.windows.net/redhat-stable/jenkins-2.121.1-1.1.noarch.rpm

    # jenkins的参数配置

    修改jenkins的启动用户(不推荐)

    # 添加deploy用户,将deploy用户设置为jenkins的启动用户

    useradd deploy

    [root@node02 ~]# vim /etc/sysconfig/jenkins

    JENKINS_USER="deploy"

    JENKINS_PORT="8080"

    [root@node02 ~]# chown -R deploy.deploy /var/lib/jenkins/

    [root@node02 ~]# chown -R deploy.deploy /var/log/jenkins/

    [root@node5 ~]# lsof -i:8080

    COMMAND   PID    USER   FD   TYPE DEVICE SIZE/OFF NODE NAME

    java    83897 jenkins  162u  IPv6  91128      0t0  TCP *:webcache (LISTEN)

    方法2:通过tomcat的方法安装jenkins(推荐)

    下载tomcat8.5

    https://archive.apache.org/dist/tomcat/tomcat-8/v8.5.39/bin/apache-tomcat-8.5.39.zip

    下载jenkins的war包

    https://mirrors.tuna.tsinghua.edu.cn/jenkins/war/2.168/jenkins.war

    # 添加deploy 作为jenkins的运行用户

    [root@node5 jenkins]# useradd deploy

    [root@node5 jenkins]# cd /usr/local/apache-tomcat-8.5.39/bin/

    [root@node5 local]# chown -R deploy.deploy /usr/local/apache-tomcat-8.5.39/

    [root@node5 local]# su - deploy

    [deploy@node5 ~]$ pwd

    /home/deploy

    [deploy@node5 ~]$ cd /usr/local/apache-tomcat-8.5.39/bin/

    [deploy@node5 bin]$ ./startup.sh

    Using CATALINA_BASE:   /usr/local/apache-tomcat-8.5.39

    Using CATALINA_HOME:   /usr/local/apache-tomcat-8.5.39

    Using CATALINA_TMPDIR: /usr/local/apache-tomcat-8.5.39/temp

    Using JRE_HOME:        /usr/java/jdk1.8.0_181-amd64

    Using CLASSPATH:       /usr/local/apache-tomcat-8.5.39/bin/bootstrap.jar:/usr/local/apache-tomcat-8.5.39/bin/tomcat-juli.jar

    Tomcat started.

    [deploy@node5 bin]$ ps -ef|grep tomcat

    deploy    53267      1 99 19:45 pts/0    00:00:04 /usr/java/jdk1.8.0_181-amd64/bin/java -Djava.util.logging.config.file=/usr/local/apache-tomcat-8.5.39/conf/logging.properties -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -Djdk.tls.ephemeralDHKeySize=2048 -Djava.protocol.handler.pkgs=org.apache.catalina.webresources -Dorg.apache.catalina.security.SecurityListener.UMASK=0027 -Dignore.endorsed.dirs= -classpath /usr/local/apache-tomcat-8.5.39/bin/bootstrap.jar:/usr/local/apache-tomcat-8.5.39/bin/tomcat-juli.jar -Dcatalina.base=/usr/local/apache-tomcat-8.5.39 -Dcatalina.home=/usr/local/apache-tomcat-8.5.39 -Djava.io.tmpdir=/usr/local/apache-tomcat-8.5.39/temp org.apache.catalina.startup.Bootstrap start

    deploy    53289  53228  0 19:45 pts/0    00:00:00 grep --color=auto tomcat

    访问:tomcat 开始进行配置

    [root@node5 ~]# cat /var/lib/jenkins/secrets/initialAdminPassword

    194816f4967541018bde5802e15da603

    安装推荐的插件

    账号密码Admin和admin

    配置邮箱

    添加凭证

    点击全局凭据

    添加凭据

    添加root凭据

    创建一个freestyle的项目

    编写描述信息

    选择参数

    输入dev和prod两个参数选项

    添加文本参数

    源代码管理

     复制gitlab代码仓库的地址

    报错的处理:

    Failed to connect to repository : Command "git ls-remote -h https://gitlab.example.com/root/test-repo.git HEAD" returned status code 128:
    stdout: 
    stderr: fatal: unable to access 'https://gitlab.example.com/root/test-repo.git/': Peer's certificate issuer has been marked as not trusted by the user.

    SSL certificate problem: unable to get local issuer certificate

    解决办法:

    在jenkins服务器中安装git

    Yum install –y git

    并执行以下命令:

    [root@node5 logs]# git config --global http.sslVerify false

    构建build配置

    选择执行shell

    执行脚本:

    #!/bin/sh

    export PATH="/bin/:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin"

    # print env variable

    echo "[INFO] print env variable"

    echo "current deployment environment is $deploy_env" >> test.properties

    echo "the build is $version" >> test.properties

    echo "[INFO] done..."

    # check test properties

    echo "[INFO] check test properties"

    if [ -s test.properties ]

    then

      cat test.properties

      echo "[INFO] done"

    else

      echo "test.properties is empty"

    fi

    echo "[INFO] build finished..."

    执行任务构建

    控制台输出

  • 相关阅读:
    检测服务器是否开启重协商功能(用于CVE-2011-1473漏洞检测)
    Wireshark解密HTTPS流量的两种方法
    text2pcap: 将hex转储文本转换为Wireshark可打开的pcap文件
    Hibernate框架(五)Hibernate主键生成策略
    HIbernate框架(四)实现添加操作
    Hibernaete框架(三)搭建hibernate环境(重点)
    Hibernate框架(二)什么是orm思想(重点)
    Hibernate框架(一)Hibernate框架是什么?
    拦截器和过滤器的区别
    谈谈java中遍历Map的几种方法
  • 原文地址:https://www.cnblogs.com/reblue520/p/10616374.html
Copyright © 2020-2023  润新知