Adding Custom Scripts to Pipelines

Adding Custom Scripts to Pipelines

To get started with creating a Pipeline, first run ops init , then enter a name and description for the pipeline at the interactive prompts. This will create a new ops.yml file in a directory named after the pipeline you created:

For example, if you enter sh-ppln-test as the Pipeline’s name at the interactive prompt, it will create a directory named sh-ppln-test under your current working directory.

Change into your new directory (e.g. cd sh-ppln-test would be used in the example above), and open the ops.yml file in your preferred text editor, e.g.:

You can then edit the ops.yml file to call a custom bash script as part of a job within the pipeline. For example, this ops.yml file will echo an environment variable, then invoke with bash:

You can then invoke ops init again in this current directory, this time with the -j or --jobs flag specified. This will cause the Ops CLI to generate the local template files needed for the jobs specified in your ops.yml:

In the newly created directory for the job template—in this case, at .ops/jobs/sh-ppln-test-build, reflecting the job pipelines[0].jobs[0].name specified in the ops.yml file—we have a Dockerfile and the support files necessary for this job to function. If you take a look at the file at .ops/jobs/sh-ppln-test-build/, you’ll see that it has lines reflecting each of the job steps in the ops.yml configuration:

Now, if you create a new script named in the directory .ops/jobs/sh-ppln-test-build/, to be invoked at runtime. Create this new script, then run ops build . and ops run . to build and run the pipeline with the custom script included:

When this is run, if everything has been configured properly, you should see the Docker image be built, and the output from running this job should reflect the output of our echo statement in ops.yml and our file: