Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use external script inside CircleCI build script

I would like to import logics from an external shell script as part of my CircleCI configuration and I'm looking for the "correct" (or best) way to do this.

Let's assume I have the following config.yml for CircleCI:

version: 2.1
jobs:
  build:
    docker:
      - image: circleci/ruby:2.5.3-node-browsers
    steps:
      - checkout
      - run:
          name: Compute some value
          command: |
            SOME_VALUE=$(foo.sh)
      - run:
          name: Reuse some value
          command: |
            echo "Hello" > /a/path/${SOME_VALUE}.txt

The overall idea is to wrap these steps into a CircleCI Orb and then have my build configuration reuse them from the Orb. But the foo.sh script cannot be packaged into the Orb itself, so I need some other way to make it accessible inside the build configuration.

So how I can include the foo.sh script (or any other script or executable) into my build process?

What I see so far (and why I don't think that's the best way to do it):

  1. From the CircleCI documentation I don't see a way to include scripts like foo.sh directly as part of an Orb.
  2. I could create a new Docker image, based upon circleci/XXX, include my script in that Docker image and call it directory. I don't really like the idea as the script has nothing to do with the Docker image it's based upon - I would just misuse Docker as transportation here.
  3. I could wget the script from a public location, store it temporarily and then call it from within the running container that is executing the build script. But loading content from a public URL and then executing doesn't feel right (and either a typo or some malicious work could lead to me executing some foreign shell script with god knows what content).
  4. I could clone some Git repository with the script inside to the local file system inside the running build container and then execute the script. Feels a little bit better than option (3).

Any ideas or best practices that I haven't thought of yet?

like image 340
Christian Seifert Avatar asked Oct 21 '25 05:10

Christian Seifert


1 Answers

So how I can include the foo.sh script (or any other script or executable) into my build process?

You package it in the orb.

Here's an example in one of circle's maintained orbs:

https://github.com/CircleCI-Public/slack-orb/blob/48638f19e8b12170027cc55f06a3a924a8f8dc2d/src/commands/notify.yml#L111

      command: <<include(scripts/notify.sh)>>

references the script in https://github.com/CircleCI-Public/slack-orb/blob/48638f19e8b12170027cc55f06a3a924a8f8dc2d/src/scripts/notify.sh

like image 150
keen Avatar answered Oct 22 '25 18:10

keen