Giter Club home page Giter Club logo

trigger-circleci-pipeline-action's Introduction

Trigger CircleCI Pipeline

Trigger your CircleCI pipelines from any event on GitHub with GitHub Actions.

How to Use

  1. Create a GitHub Action's workflow for the desired CircleCI pipeline.

    Do this by adding a workflow YAML file (we'll use main.yml) to ./.github/workflows.

    A release trigger is shown in this example. Try any of the GitHub events for triggering workflows: https://docs.github.com/en/actions/learn-github-actions/events-that-trigger-workflows

    Select a custom name and id for the step for additional contextual metadata in your CircleCI pipeline

on:
  release:
    types: [published]
jobs:
  trigger-circleci:
    runs-on: ubuntu-latest
    steps:
      - name: <customize name>
        id: <customize id>
        uses: CircleCI-Public/[email protected]
        env:
          CCI_TOKEN: ${{ secrets.CCI_TOKEN }}
  1. Create an encrypted secret named CCI_TOKEN containing the Personal API Token that will be used to trigger the pipelines. This is suggested to be a machine user.

  2. Add the Pipeline Parameter definitions to your CircleCI config. This data will be entered by the GitHub Action when triggered.

    Add the following to the top of your .circleci/config.yml file. Ensure you are specifying version 2.1

    version: 2.1
    parameters:
      GHA_Actor:
        type: string
        default: ""
      GHA_Action:
        type: string
        default: ""
      GHA_Event:
        type: string
        default: ""
      GHA_Meta:
        type: string
        default: ""
  3. Use the Pipeline Parameter data to run workflows conditionally.

    See: Examples

Inputs

Optional input parameters that allow you to specify additional metadata.

GHA_Meta

required: false

description: An optional additional metadata parameter. Will be available on the CircleCI pipeline as GHA_Meta.

jobs:
  trigger-circleci:
    runs-on: ubuntu-latest
    steps:
      - name: <customize name>
        id: <customize id>
        uses: CircleCI-Public/[email protected]
        with:
          GHA_Meta: "<custom data>"
        env:
          CCI_TOKEN: ${{ secrets.CCI_TOKEN }}

target-slug

required: false

description: The CircleCI project slug of the target project (ex: github/<org>/<repo>). If not specified, the slug of the current GitHub repository will be used.

jobs:
  trigger-circleci:
    runs-on: ubuntu-latest
    steps:
      - name: <customize name>
        id: <customize id>
        uses: CircleCI-Public/[email protected]
        with:
          target-slug: "gh/<org>/<repo>" # Will trigger the pipeline for external project
        env:
          CCI_TOKEN: ${{ secrets.CCI_TOKEN }}

Outputs

Field Data Type Description
id string (uuid) The unique ID of the pipeline.
state string (Enum: "created" "errored" "setup-pending" "setup" "pending") The current state of the pipeline.
number integer (int64) The number of the pipeline.
created_at string (date-time) The date and time the pipeline was created.

Things To Know

GitHub Actions runs alongside native CircleCI integration.

By default, when a repository is connected to CircleCI, if the workflows within that project's configuration does not specify any conditionals or filters that would otherwise prevent execution, the workflow will execute on every push event by default.

This may mean it is possible to accidentally run a job twice, once on the push event from CircleCI, as well as other events triggered by the GitHub Action.

To prevent double execution

If you are relying on GitHub Actions to provide all of your API triggers, ensure that each of your CircleCI configuration's workflows contains a conditional limiting it's execution to only the GitHub Action trigger.

Example

workflows:
  # This workflow is set to be conditionally triggered,
  # only via the GitHub Action.
  # With no other unfiltered workflows, normal push events will be ignored.
  test:
    when: << pipeline.parameters.GHA_Action >>
    jobs:
      - test

trigger-circleci-pipeline-action's People

Contributors

kyletryon avatar mattlewis92 avatar circleci-secops avatar hikaru-nakayama avatar whatisdot avatar zackse avatar pepesenaris avatar kelvintaywl avatar headfox avatar nick-fields avatar nrakochy avatar peterhewat avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.