分支名习惯用feature/xxxxx等格式,每次在CI的build 镜像编译阶段总是报如下错误:
invalid argument "hub.docker.org/xxxx/xxxx:feature/xxxx/xxxx" for "-t, --tag" flag: invalid reference format
查看docker build和docker tag文档,确定tag格式,给build的stage阶段加上only字段限制
docker tag | Docker Documentation
Build:
image: hub.docker.org/xxxx/xxxx:1.16 # 可以使用image指定该步骤使用特定的镜像来运行
stage: Build
only:
# https://docs.docker.com/engine/reference/commandline/tag/
# A tag name must be valid ASCII and may contain lowercase and uppercase letters, digits, underscores, periods and dashes.
# A tag name may not start with a period or a dash and may contain a maximum of 128 characters.
- /^[\w_][\w\-_\\.]{0,128}$/
except:
- /.*[\/\\].*/
script:
- echo ${CI_COMMIT_REF_NAME}
可以在正则表达式网站(gitlab ci使用ruby正则表达式验证)进行在线验证Rubular: a Ruby regular expression editor

在使用GitLab CI进行自动化构建时,遇到因分支名格式(如feature/xxxxx)导致的docker build错误。通过查阅docker build和docker tag的文档,了解到可以使用only字段限制tag格式。采用Ruby正则表达式在CI的build阶段进行校验,确保符合要求,避免编译错误。推荐使用在线正则表达式验证工具如Rubular进行测试。
最低0.47元/天 解锁文章
548

被折叠的 条评论
为什么被折叠?



