Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 20 additions & 1 deletion incubating/pipeline-trigger-merge/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,23 @@ MergeTriggersIntoPipelines:
SPEC: spec.yml
ONLY_CHANGED: true
TRIGGERS_SUBDIR: "triggers"
```
```

## Testing and Debugging

In order to speed up development (or debugging), we recommend to run the image
locally and mounting the your local folder to your container.

To do that,

1. we will be running docker run (be sure the daemon is running on your local box)
2. mount local folder there your spec and triggers are located
3. mount the .cfconfig file (to be able to call the CLI)
4. Pass variables as environment variables

```sh
docker run -v ~/.cfconfig:/root/.cfconfig -v $(pwd)/sample:/foo \
-e SPEC=/foo/spec.yml \
-e TRIGGERS='/foo/TRIGGERS /foo/trig1.yml' \
quay.io/codefreshplugins/pipeline-trigger-merge:1.1.0
```
37 changes: 33 additions & 4 deletions incubating/pipeline-trigger-merge/merge.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#/bin/#!/usr/bin/env bash
#!/bin/bash

process_dir() {
echo "Processing trigger directory $1"
Expand All @@ -25,11 +25,40 @@ process_file() {
fi
echo "WARNING: Unknown trigger file $1"
}
export curdir=`pwd`
export count=1

# exit on error
set -e
echo "pipeline-trigger-merge v1.1.0"

count=1
echo "Merging pipeline spec $SPEC with triggers $TRIGGERS"
for f in `echo $TRIGGERS` ; do
# is path absolute
if [[ "$f" = /* ]] ; then
curdir="/"
else
curdir=`pwd`
fi
process_file $f
done

echo "Creating/Updating final pipeline"
codefresh create pipeline -f $SPEC || codefresh replace -f $SPEC

# Get pipeline name
echo "Checking if pipeline already exists"
name=$(yq '.metadata.name' $SPEC)
codefresh get pip $name > pipeline.log 2>&1 || true

#Check if pipeline exists
if [ `grep -c PIPELINE_NOT_FOUND pipeline.log` -eq 0 ] ; then
echo "Updating final pipeline"
cmd="codefresh replace -f $SPEC"
else
echo "Creating final pipeline"
cmd="codefresh create pipeline -f $SPEC"
fi

# Check for error when creating/updating the pipeline
echo "Checking for errors"
$cmd 2>&1 | tee pipeline.log
exit `grep -c 'Yaml validation errors' pipeline.log`
1 change: 1 addition & 0 deletions incubating/pipeline-trigger-merge/sample/spec.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ spec:
build:
title: "Building Docker image"
type: "build"
registry: docker
image_name: "codefresh-io/cli"
working_directory: "${{clone}}"
tag: "latest"
Expand Down
19 changes: 17 additions & 2 deletions incubating/pipeline-trigger-merge/step.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ kind: step-type
version: '1.0'
metadata:
name: pipeline-trigger-merge
version: 1.0.2
version: 1.1.0
isPublic: true
description: >-
Merge a pipeline spec and a list of triggers (files or directories) to
Expand Down Expand Up @@ -65,14 +65,29 @@ spec:
"TRIGGERS_SUBDIR": {
"type": "string",
"description": "The subdirectory that holds a pipeline's triggers if looping. Defaults to 'triggers'."
},
"REGISTRY": {
"type": "string",
"description": "Docker Registry for step's image.",
"default": "quay.io"
},
"IMAGE": {
"type": "string",
"description": "Image name for step's image.",
"default": "codefreshplugins/pipeline-trigger-merge"
},
"IMAGE_TAG": {
"type": "string",
"description": "Image tag for step's image.",
"default": "1.1.0"
}
}
}

stepsTemplate: |-
pipeline-trigger-merge:
name: pipeline-trigger-merge
image: quay.io/codefreshplugins/pipeline-trigger-merge:1.0.2
image: '[[.Arguments.REGISTRY]]/[[.Arguments.IMAGE]]:[[.Arguments.IMAGE_TAG]]'
environment:
[[ range $key, $val := .Arguments ]]
- '[[ $key ]]=[[ $val ]]'
Expand Down