Jenkins 部署项目

1. 安装 Jenkins

# 安装
sudo wget -O /etc/yum.repos.d/jenkins.repo \
    https://pkg.jenkins.io/redhat-stable/jenkins.repo
sudo rpm --import https://pkg.jenkins.io/redhat-stable/jenkins.io.key
sudo yum upgrade
sudo systemctl daemon-reload

# 启动
systemctl start jenkins

# 停止
systemctl stop jenkins

# 故障解决
systemctl status jenkins # 查看启动文件
vim /etc/rc.d/init.d/jenkins # 修改 java 环境地址

# https 配置
https://jansipke.nl/enable-https-jenkins/
复制代码

2. 安装 Jenkins 插件

  1. git
    This plugin integrates with jenkins
  2. NodeJs
    NodeJS plugin executes NodeJS script a build step.
  3. Publish Over SSH
    Send build artifacts over SSH

3. 配置 Global Tool

  1. Maven Configuration

  2. JDK

  3. Git

  4. Maven

  5. NodeJS

4. 配置 Credentials

add credential > select username with password / ssh
复制代码

5. 新建项目

  1. New Item
    Enter an item name -> select Freestyle project

  2. General
    1. 填写 description
    2. 选择 JDK 版本

  3. Soruce Code Management
    1. 选择 Git
    2. 填写 url 地址,选择 Credentials

  4. Build Triggers
    手动触发,这里不勾选任何选项

  5. Build Environment
    1. 选择 Provide Node & npm bin/folder to PATH
    2. 值选择默认即可

  6. Build
    1. 选择 Execute Shell
    2. 起草 shell

    # 安装依赖
    npm install
    # 打包
    npm run build
    # 打印当前目录
    pwd
    
    # 拷贝 dist 目录到/usr/local/vue2-admin
    cp ./dist /usr/local/vue2-admin -R
    复制代码
  7. Post-build Actions
    1. 选择 Send build artifacts over SSH
    2. 填写 主机

    aliyun_fw
    复制代码

    3. Source files

    *nginx.conf,*Dockerfile,dist/**/*
    复制代码

    4. Remove prefix

    # 相当于拷贝完 dist 目录后,删除 dist 目录,但保留 dist 目录下的内容
    dist
    复制代码

    5. Remote directory

    # 这个文件夹必须存在
    /usr/local/vue2-admin
    复制代码

    6. Exec command

    cd /usr/local/vue2-admin/
    docker build -t vue2-admin .
    复制代码

8. Email Notification

选择 E-mail Notification
填写 email地址
勾选,失败也发送
复制代码
© 版权声明
THE END
喜欢就支持一下吧
点赞0 分享