Giglab CI/CD

.gitlab-ci.yml

打包结构是 将前端代码放到后端的static目录。

步骤:

tags:shell 是配置号的docker

从前端代码编译->打jar->上传ftp

# This file is a template, and might need editing before it works on your project.
# This is a sample GitLab CI/CD configuration file that should run without any modifications.
# It demonstrates a basic 3 stage CI/CD pipeline. Instead of real tests or scripts,
# it uses echo commands to simulate the pipeline execution.
#
# A pipeline is composed of independent jobs that run scripts, grouped into stages.
# Stages run in sequential order, but jobs within stages run in parallel.
#
# For more information, see: https://docs.gitlab.com/ee/ci/yaml/index.html#stages
#
# You can copy and paste this template into a new `.gitlab-ci.yml` file.
# You should not add this template to an existing `.gitlab-ci.yml` file by using the `include:` keyword.
#
# To contribute improvements to CI/CD templates, please follow the Development guide at:
# https://docs.gitlab.com/ee/development/cicd/templates.html
# This specific template is located at:
# https://gitlab.com/gitlab-org/gitlab/-/blob/master/lib/gitlab/ci/templates/Getting-Started.gitlab-ci.yml
variables:
  pageHome: project-pages
  serverHome: project-server


stages:          # List of stages for jobs, and their order of execution
  - install
  - copyfiles
  - build
  - test
  - deploy

cache:
  paths:
    - ${pageHome}
    - $serverHome
    - ${pageHome}/node_modules
    - ${pageHome}/build
    - ${pageHome}/dist
    - app.jar

before_script:
  - echo "Check Envirenment..."
  - echo "Hello, $GITLAB_USER_LOGIN!"
  - curl --help 
  - uname -a


#编译前端vue3 
npm-install-job:   # This job also runs in the install stage.
  stage: install    # It can run at the same time .
  image: node:18     
  tags:
    - shell
  script:
    - echo "firstly, build pageHome by package.json ..."
    - echo "----------------------------"
    - cd ${pageHome}   #- sleep 10
    - node -v
    - npm -v
    - ls -a
    - npm install 
    - npm run build
    - ls -a
    - cd ..   # move to Home Dir
    - echo "install completely."
    - echo "Ready to next step..."

# 将前端build 的内容全部移动到后端的static目录
copyfiles-job:   # This job also runs in the copyfiles stage,, which runs secondly
  stage: copyfiles    # It can run ...
  tags:
    - shell
  script:
    - echo "secondly, move ${pageHome}/dist/** to ./${serverHome}/src/main/resources/static/"
    - echo "----------------------------"
    - if [ -d "./${serverHome}/src/main/resources/static/" ]; then
        rm -rf "./${serverHome}/src/main/resources/static/" ;
      fi;
    - ls
    - cp -r "./${pageHome}/dist/" "./${serverHome}/src/main/resources/static/"
    - cd ./${serverHome}/src/main/resources/static/
    - ls
    - echo "Copy files completely."
    - echo "Ready to next step..."


# 打jar包
build-job:       # This job runs in the build stage, which runs thirdly.
  stage: build
  image: adoptopenjdk/maven-openjdk8
  tags:
    - shell
  script:
    - echo "thirdly ,build pom.xml for java home"
    - echo "----------------------------"
    - java -version
    - mvn -v
    # - ls
    # - cd ./${serverHome}/src/main/resources/static/
    # - ls
    - echo "take a break for a while..."
    - sleep 1  
    - cd ${serverHome}
    - mvn clean package -Dmaven.test.skip=true
    - cd ..
    - echo "finally, rename the jar name" 
    - echo "----------------------------"
    - if [ -e "app.jar" ];
        then rm "app.jar";
      fi;
    - cp "./${serverHome}/target/spark-server-0.0.1-SNAPSHOT.jar" "app.jar"
    - ls -a
    - echo "Compile complete."
    - echo "Ready to next step..."

#测试,没啥用
lint-test-job:   # This job also runs in the test stage.
  stage: test    # It can run at the same time as unit-test-job (in parallel).
  tags:
    - shell
  script:
    - echo "nothing to do!"
    - echo "Ready to next step..."
    - if [ -e "app.jar" ];
        then echo "app.jar is ready !";
      else 
        echo "the jar not be ok.";
      fi;
    - echo "Ready to next step..."    #- sleep 10 


# 上次到ftp
deploy-job:      # This job runs in the deploy stage.
  stage: deploy  # It only runs when *both* jobs in the test stage complete successfully.
  tags:
    - shell
  script:
    - echo "Deploying application..."
    - echo "${FTPS_URL}"
    - echo "${FTPS_USERNAME}"
    - echo "${FTPS_PASSWORD}"
    - echo "${CI_PROJECT_DIR}"
    - CURRENT_TIME=$(date +"%Y-%m-%d_%H-%M-%S")
    - echo "$CURRENT_TIME"
    - echo "$CI_PIPELINE_CREATED_AT"
    - apt-get update -qy
    - apt-get install -qy lftp
    - echo "show gitLab local files:"  
    - ls 
    - lftp ${FTPS_URL} -u ${FTPS_USERNAME},${FTPS_PASSWORD} <<END_SCRIPT
    - mv app.jar ./backup-cicd/app-${CURRENT_TIME}.jar;
    - put ${CI_PROJECT_DIR}/app.jar;
    - exit;

  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值