CloudBees action: Register an artifact deployed to an environment

2 minute read

Use this action to report artifact-related data to an environment from a CloudBees platform workflow run, for artifact traceability purposes.

This action version (v2.0) is the most recent release of the action. Previous releases are deprecated. Version 2.0 replaces multiple required inputs with a single parameter, artifact_id.

Prerequisites

Before using this action, you must first register the artifact you plan to deploy to an environment. This registration saves the artifact information to the CloudBees platform.

Do one of the following to save your artifact information to the platform:

All CloudBees action repositories are listed at CloudBees, Inc. on GitHub.

Inputs

Table 1. Input details
Input name Data type Required? Description

artifact_id

String

Yes

The unique identifier of the artifact ID output from the CloudBees platform.

target-environment

String

Required if no job-level environment is specified.

The environment where the deployment is located. The target-environment value overrides the jobs.<job_id>.environment value.

labels

String

No

A comma-separated list of artifact labels.

Usage examples

Basic example

The following is a basic example of using the action:

jobs: register_artifact_version_to_test_env: environment: test_env steps: - name: Register deployed artifact uses: cloudbees-io/register-deployed-artifact@v2 with: artifact_id: 1234abcd-56ef-ab78-9012-cdef78903456 target-environment: test_env

Using optional inputs

The following example specifies artifact labels:

jobs: register_artifact_version_to_qa_env: environment: qa_env steps: - name: Register deployed artifact with labels uses: cloudbees-io/register-deployed-artifact@v2 with: artifact_id: 1234abcd-56ef-ab78-9012-cdef78903456 labels: label1,label2

Full workflow example with Kaniko

This example publishes an image with Kaniko, and then reports the data to the platform.

name: Deployment workflow on: workflow_dispatch: jobs: build: steps: - uses: docker://alpine/git:latest run: | git config --global --add safe.directory /cloudbees/workspace - uses: cloudbees-io/checkout@v1 name: checkout - uses: docker://golang:1.20 name: Build Go app kind: build run: | go build -v ./... - uses: cloudbees-io/configure-oci-credentials@v1 name: Set up Docker Hub registry kind: deploy with: registry: index.docker.io username: ${{ vars.DOCKER_USERNAME }} password: ${{ secrets.DOCKER_TOKEN }} - name: Push image to OCI registry id: push-image uses: cloudbees-io/kaniko@v1 with: destination: index.docker.io/myorg/my-sample-go-app:${{cloudbees.version}} deploy: steps: - name: Register deployed artifact uses: cloudbees-io/register-deployed-artifact@v2 with: artifact_id: ${{ fromJSON(steps.push-image.outputs.artifact-ids)[format('index.docker.io/myorg/my-sample-go-app:{0}', cloudbees.version)] }} target-environment: my-env

Full workflow example with registering a build artifact

The following workflow uses the Register a build artifact action to register the build artifact to the platform. Then it deploys the artifact to the Docker test target environment and publishes evidence to the platform.

apiVersion: automation.cloudbees.io/v1alpha1 kind: workflow name: My workflow on: workflow_dispatch: jobs: build: steps: - name: id: my-build uses: cloudbees-io/register-build-artifact@v1 with: name: art1 version: ${{ cloudbees.version }} url: docker.io/my-app/art1::${{ cloudbees.version }} deploy: steps: - uses: cloudbees-io/register-deployed-artifact@v2 with: artifact_id: ${{ steps.build.outputs.artifact-id }} target-environment: test needs: build publish-evidence: steps: - name: publish evidence with: content: This is evidence uses: cloudbees-io/publish-evidence-item@v1 needs: deploy