-
Notifications
You must be signed in to change notification settings - Fork 0
CI Setup
Previous: Continuous Integration / Deployment
In this section, we'll make a Concourse pipeline to test our app. If you have not deployed Concourse locally yet, follow the instructions on Deploy Concourse.
First, make a ci
directory at the root of your repository. Create a pipeline.yml
file.
The pipeline is going to need access to the code, so add a resource:
resources:
- name: repo
type: git
source:
uri: {{repo-url}}
branch: master
We'll need something for the pipeline to actually do, so let's add a job:
jobs:
- name: test
plan:
# Fetch files from the repository.
- get: repo
trigger: true
# In parallel
- aggregate:
# Run unit tests
- task: test
file: repo/ci/tasks/test.yml
params:
PROJECT_NAME: NotesApp.Tests
# Run integration tests
- task: integration-test
file: repo/ci/tasks/test.yml
params:
PROJECT_NAME: NotesApp.IntegrationTests
Because we're passing in PROJECT_NAME
to test.yml
, we can re-use the same files for both types of tests. test.yml
and test.sh
are as follows:
ci/tasks/test.yml
:
platform: linux
image_resource:
type: docker-image
source:
repository: microsoft/dotnet
tag: 2.2-sdk
inputs:
- name: repo
run:
path: ./repo/ci/tasks/test.sh
We take in a single input, the repository, and execute our test.sh
script.
ci/tasks/test.sh
:
#!/bin/bash
set -ex
pushd repo
pushd $PROJECT_NAME
dotnet test
popd
popd
If you're not familiar with pushd
and popd
, they behave similarly to cd
except that they keep track of history of what was navigated to with pushd
and can popd
back to it later. Once we're in the correct directory, we simply need to run dotnet test
.
Add a variables.yml
file to hold the value of our variable, {{repo-url}}
. It should look like:
repo-url: https://github.com/xtreme-steve-elliott/NotesApp.git
The variables.yml
file should not be tracked in source control once meaningful credentials are stored in it. At that point, open the .gitignore
on the repository root, and add an entry to ignore the file:
ci/variables.yml
Push up the code since the pipeline will need to reference the test.yml
and test.sh
inside the ci
directory.
Now, using the fly
cli from the ci
directory, deploy the pipeline:
fly -t targetname set-pipeline -p pipeline -c pipeline.yml -l variables.yml
Where targetname
is the name of the target you setup in Deploy Concourse. This creates a pipeline called pipeline
using the configuration at ci/pipeline.yml
and loads variables from ci/variables.yml
Unpause the pipeline to start it.
This can be accomplished via:
fly -t targetname unpause-pipeline -p pipeline
Git Tag: ci-setup
Up Next: CF Deployment