我有这个drone.yml,它运行良好,并生成一个码头映像。我正在建立与两个标签的码头形象。
我想要做的是在第一个标记(GitHub中提交的SHA)中附加YYYY DD_HH格式的图像创建日期和时间。
---
name: api-graph-base
kind: pipeline
type: docker
steps:
- name: push-azure-nonprod
when:
event:
- push
- pull_request
branch:
- master
image: plugins/docker
settings:
username: abc
password:
from_secret: xyz
repo: nonprodazure/graph-base-api
build_args:
- LOG_LEVEL=debug
registry: nonprodregistry.azurecir.io
custom_dns: [100.100.100.100, 99.99.99.99]
tags:
- '${DRONE_BUILD_FINISHED}-${DRONE_COMMIT}'
- latest
dockerfile: Dockerfile无人机构建日志中的图像标记:
您可以在日志中看到附加在docker图像标记名称中的UNIX时间戳(1600986079)。如何将${DRONE_BUILD_FINISHED} - Unix时间戳的值更改为DateTime人类可读的字符串格式(YYYY DD_HH)?
发布于 2020-09-25 20:56:11
这就是我需要做的,以人类可读的格式而不是UNIX格式获取日期/时间。
---
name: api-graph-base
kind: pipeline
type: docker
steps:
- name: send-tags-to-tags-file
image: node
when:
event:
- push
- pull_request
commands:
- echo -n "$(date +'%Y-%m-%d_%H-%M')_${DRONE_COMMIT}, latest" > .tags
- name: push-azure-nonprod
when:
event:
- push
branch:
- master
image: plugins/docker
settings:
username: abc
password:
from_secret: xyz
repo: nonprodazure/graph-base-api
build_args:
- LOG_LEVEL=debug
registry: nonprodregistry.azurecir.io
custom_dns: [100.100.100.100, 99.99.99.99]
dockerfile: Dockerfile下面两个标签为码头形象创建。第二个标签名现在包含所需的日期-时间格式。

解决方案:
如果需要在同级进程(管道步骤)之间共享数据,则需要通过写入磁盘和从磁盘读取这些信息来共享这些信息。停靠插件将自动从.tags文件中读取标记。不能在一个进程中创建环境变量,而不能在同级进程中读取该环境变量。
参考文献:
https://stackoverflow.com/questions/64062210
复制相似问题