regex - Github Actions / 从分支名称中提取 TicketID
问题描述
您当前可以通过以下方式设置环境变量:
- name: Configure Environment Variables
uses: allenevans/set-env@v1.0.0
with:
CDN_PATH: app-foo/${{ github.run_id }}
CDN_URL: 'https://cdn.mycompany.com'
JIRA_TICKET_ID: ${{ match(github.ref, ...) }} # How can I extract a string from a branch name?
- https://docs.github.com/en/actions/reference/context-and-expression-syntax-for-github-actions#functions
- https://docs.github.com/en/actions/reference/context-and-expression-syntax-for-github-actions
如何从分支名称中提取字符串?
JIRA_TICKET_ID: ${{ match(github.ref, ...) }}
解决方案
我不相信 github 操作中有内置函数可以做到这一点。但是你可以在你的行动之前运行一个步骤来为你获取 jira 票。
注意:您需要将 sed 正则表达式修改为获取票证的正则表达式。现在它只从 ref 中获取分支名称
- id: getjiraticket
run: echo "::set-output name=jiraticketid::`echo "${{ github.ref }}" | sed 's/.*\///'`"
- name: Configure Environment Variables
uses: allenevans/set-env@v1.0.0
with:
CDN_PATH: app-foo/${{ github.run_id }}
CDN_URL: 'https://cdn.mycompany.com'
JIRA_TICKET_ID: ${{ steps.getjiraticket.outputs.jiraticketid }}
推荐阅读
- ios - 根据另一个变量的值更改变量的值
- mule - 我正在使用 SDK 构建一个 mule4 自定义连接器。如何在操作类中获取 mule 消息对象的引用?
- reactjs - Docker + Flask + React + Axios + http-proxy-middleware 失败并显示“尝试代理到...时发生错误”
- python - 从 PHP 运行 Python,状态 0,不工作
- javascript - jquery自动更新金额
- dataweave - 如何使用 MuleSoft 在平面文件中创建标题?
- python-3.x - 使用 Pyinstaller 创建的 Python3 人脸识别 windows exe 应用程序不起作用
- html - 使用问题
- azure - 如何在 Azure 上为 Angular 项目创建发布管道
- android - 如何在firebase实时数据库android中创建嵌套子节点