demo/.woodpecker.yaml

56 lines
2.1 KiB
YAML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# .woodpecker.yaml
steps:
- name: Java 构建
image: docker.m.daocloud.io/library/maven:3.9.6-eclipse-temurin-17
pull: true
commands:
- mvn clean package -DskipTests
volumes:
- /tmp/maven-cache:/root/.m2
when:
event: [push, pull_request]
branch: master
- name: 镜像构建与推送
image: docker.m.daocloud.io/woodpeckerci/plugin-docker-buildx:latest
volumes:
- /var/run/docker.sock:/var/run/docker.sock
settings:
repo: registry.cn-zhangjiakou.aliyuncs.com/abhors/demo
tags: latest
registry: registry.cn-zhangjiakou.aliyuncs.com
username:
from_secret: aliyun_acr_username
password:
from_secret: aliyun_acr_password
mirror: https://docker.m.daocloud.io
when:
event: push
branch: master
- name: 远程终端部署
image: appleboy/drone-ssh
settings:
host:
from_secret: 136_ssh_host
username:
from_secret: 136_ssh_user
password:
from_secret: 136_ssh_password
port: 22
# 👇 完美修复 1彻底干掉外层的 environment
# 直接使用插件原生的 secrets 属性,安全导入系统里的这两个密文
secrets: [ aliyun_acr_username, aliyun_acr_password ]
# 👇 完美修复 2告诉插件在通过 SSH 连上 136 后,把上面这两个官方变量注入到远程终端里
envs: [ aliyun_acr_username, aliyun_acr_password ]
script:
# 注意:因为使用的是 secrets 原生注入,远程终端里的变量名直接叫 $aliyun_acr_username 和 $aliyun_acr_password
- docker login --username "$aliyun_acr_username" --password "$aliyun_acr_password" registry.cn-zhangjiakou.aliyuncs.com
- docker stop demo-container || true
- docker rm demo-container || true
- docker pull registry.cn-zhangjiakou.aliyuncs.com/abhors/demo:latest
- docker run -d --name demo-container -p 8080:8080 --restart always registry.cn-zhangjiakou.aliyuncs.com/abhors/demo:latest
# 👇 完美修复 3补上 when 过滤条件,消除 bad_habit 警告
when:
event: push
branch: master