Server CI/CD
Tip
- Operating System: Ubuntu 20.04 LTS
- Server Requirements: Minimum 2 cores 4GB RAM, Recommended 4 cores 8GB RAM
GitHub Actions
name: Build and Deploy Server
on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set up JDK
uses: actions/setup-java@v2
with:
java-version: '17'
distribution: 'adopt'
- name: Build with Maven
run: mvn -B package --file pom.xml
- name: Deploy
uses: appleboy/scp-action@master
with:
host: ${{ secrets.HOST }}
username: ${{ secrets.USERNAME }}
key: ${{ secrets.SSH_KEY }}
source: "target/*.jar"
target: "/opt/bytedesk/"
GitLab CI
stages:
- build
- deploy
build:
stage: build
image: maven:3.8-openjdk-17
script:
- mvn package
artifacts:
paths:
- target/*.jar
deploy:
stage: deploy
script:
- rsync -avz --delete target/*.jar user@server:/opt/bytedesk/
only:
- main
Jenkins Pipeline
pipeline {
agent any
tools {
jdk 'JDK 17'
maven 'Maven 3'
}
stages {
stage('Build') {
steps {
sh 'mvn clean package'
}
}
stage('Deploy') {
steps {
sh 'rsync -avz --delete target/*.jar user@server:/opt/bytedesk/'
}
}
}
}