Skip to main content

compose-output

compose-output is a step that composes a new output from one or more existing outputs. This step can be useful when subsequent steps need to reference a combination of outputs from previous steps, or to allow a PromotionTask to provide easy access to outputs from the steps it contains.

Configuration​

The compose-output step accepts an arbitrary set of key-value pairs, where the key is the name of the output to be created and the value is arbitrary and can be an Expression Language expression.

Output​

The dynamic outputs of the compose-output step are the outputs that it composes according to its configuration.

Examples​

In this example, a pull request link is constructed and sent to Slack. First, a pull request is opened using the git-open-pr step. Then, the compose-output step creates a new output named URL by combining the repository URL with the PR number to form a complete PR link. Finally, the http step uses this composed URL to send a formatted message to a Slack channel using Slack's API.

vars:
- name: repoURL
value: https://github.com/example/repo
steps:
# Clone, prepare the contents of ./out, commit, push as part of a `push` step etc...
- uses: git-open-pr
as: open-pr
config:
repoURL: ${{ vars.repoURL }}
sourceBranch: ${{ task.outputs.push.branch }}
targetBranch: stage/${{ ctx.stage }}
- uses: compose-output
as: pr-link
config:
url: ${{ vars.repoURL }}/pull/${{ task.outputs['open-pr'].pr.id }}
- uses: http
config:
method: POST
url: https://slack.com/api/chat.postMessage
headers:
- name: Authorization
value: Bearer ${{ secret('slack').token }}
- name: Content-Type
value: application/json
body: |
${{ quote({
"channel": "C123456",
"blocks": [
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "A new PR has been opened: " + task.outputs['pr-link'].url
}
}
]
}) }}
note

In the above example, it is assumed that the steps are part of a PromotionTask. Because of this, it uses the task.outputs syntax to reference the outputs of the git-open-pr step.

If you are using the compose-output step in a regular Promotion template, you can omit the task prefix and use outputs instead. For example, outputs['open-pr'].pr.url instead of task.outputs['open-pr'].pr.url.