Skip to content

Commit

Permalink
Jenkins Pipeline creation in makefile
Browse files Browse the repository at this point in the history
  • Loading branch information
BraisVQ committed Sep 25, 2024
1 parent 3d7ae16 commit b7dd84e
Show file tree
Hide file tree
Showing 3 changed files with 146 additions and 3 deletions.
18 changes: 15 additions & 3 deletions tests/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,15 @@ MAKEFLAGS += --no-builtin-rules
### By default we test all quickstarters located in ods-quickstarters
QS := ods-quickstarters/...

# Load environment variables from .env file
include ../../ods-configuration/ods-core.env
export $(shell sed 's/=.*//' ../../ods-configuration/ods-core.env)

### By default we do not parallelize tests
PARALLEL := 1
PROJECT := unitt
SONAR_PROFILE := "Sonar way"
QUICKSTARTER_REPOSITORY := ods-quickstarters

## Full test of existing ODS core installation. Caution: Creates UNITT project and ODSVERIFY project.
test: smoketest verify test-create-projects
Expand All @@ -34,22 +40,28 @@ test-create-projects:
@(./create-projects-test.sh)
.PHONY: test-create-projects

## Run quickstarter tests within existing ODS installation. Depends on UNITT project.
## Create Jenkins pipeline using REST API
jenkins-pipeline:
@(envsubst < jenkinsPipelineCreation.sh)
@(./jenkinsPipelineCreation.sh -p $(PROJECT) -q $(QUICKSTARTER_REPOSITORY) -s $(SONAR_PROFILE))
.PHONY: jenkins-pipeline

## Run quickstarter tests within existing ODS installation. Depends on UNITT project (default).
test-quickstarter:
@(./quickstarter-test.sh -p $(PROJECT) -q $(QS) -pa $(PARALLEL))
.PHONY: test-quickstarter

## Install tools required for tests.
prep-tools:
which go-junit-report || go get github.com/jstemmer/go-junit-report
which golangci-lint || curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(shell go env GOPATH)/bin v1.50.0
which golangci-lint || curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(shell go env GOPATH)/bin v1.60.1
.PHONY: prep-tools

## Lint
lint:
echo "Checking code ..."
golangci-lint --version
golangci-lint run --go=1.18
golangci-lint run --go=1.23
.PHONY: lint

### HELP
Expand Down
76 changes: 76 additions & 0 deletions tests/golden-test-pipeline.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
apiVersion: template.openshift.io/v1
kind: Template
parameters:
- name: PROJECT
displayName: Application
description: The name of the application project.
required: true
- name: ODS_GIT_REF
displayName: Git branch
description: The git branch to use for the pipeline.
required: true
- name: ODS_IMAGE_TAG
displayName: Agent tag
description: The tag for the jenkins golang agent.
required: true
- name: ODS_NAMESPACE
displayName: ODS namespace
description: The ods namespae to fetch the jenkins agent. Include "-cd" if the ODS Namespace is not ods as default
required: true
- name: BITBUCKET_URL
displayName: Bitbucket server URL
description: The Bitbucket server URL.
required: true
- name: ODS_BITBUCKET_PROJECT
displayName: ODS Bitbucket project
description: The ODS Bitbucket project.
required: true
- name: SONAR_QUALITY_PROFILE
displayName: SonarQube Quality Profile
description: SonarQube Quality Profile.
required: true
- name: QuickstarterRepository
displayName: Quickstarter repository
description: Quickstarter repository.
required: true
objects:
- apiVersion: build.openshift.io/v1
kind: BuildConfig
metadata:
labels:
template: golden-test-pipeline
name: '${PROJECT}-golden-test'
spec:
failedBuildsHistoryLimit: 5
runPolicy: Serial
source:
git:
ref: ${ODS_GIT_REF}
uri: '${BITBUCKET_URL}/${ODS_BITBUCKET_PROJECT}/ods-core.git'
sourceSecret:
name: cd-user-with-password
type: Git
strategy:
jenkinsPipelineStrategy:
env:
- name: Quickstarter
value: ''
- name: QuickstarterRepository
value: '${QuickstarterRepository}'
- name: quickstarterRef
value: '${ODS_GIT_REF}'
- name: Project
value: '${PROJECT}'
- name: ODS_NAMESPACE
value: '${ODS_NAMESPACE}'
- name: ODS_URL
value: '${BITBUCKET_URL}/${ODS_BITBUCKET_PROJECT}'
- name: JENKINS_AGENT_TAG
value: '${ODS_IMAGE_TAG}'
- name: SONAR_QUALITY_PROFILE
value: '${SONAR_QUALITY_PROFILE}'
- name: excludedQuickstarters
value: ''
jenkinsfilePath: Jenkinsfile
type: JenkinsPipeline
successfulBuildsHistoryLimit: 5
55 changes: 55 additions & 0 deletions tests/jenkinsPipelineCreation.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#!/usr/bin/env bash
set -eux

PROJECT=""
QuickstarterRepository=""
SONAR_QUALITY_PROFILE=""
ODS_GIT_REF="$ODS_GIT_REF"
BITBUCKET_URL="$BITBUCKET_URL"
ODS_NAMESPACE="$ODS_NAMESPACE"
ODS_IMAGE_TAG="$ODS_IMAGE_TAG"
ODS_BITBUCKET_PROJECT="$ODS_BITBUCKET_PROJECT"

# Override ods configuration (optional)
while [[ "$#" > 0 ]]; do case $1 in
-g=*|--ods-git-ref=*) ODS_GIT_REF="${1#*=}";;
-g|--ods-git-ref) ODS_GIT_REF="$2"; shift;;

-b=*|--bitbucket=*) BITBUCKET_URL="${1#*=}";;
-b|--bitbucket) BITBUCKET_URL="$2"; shift;;

-n=*|--ods-namespace=*) ODS_NAMESPACE="${1#*=}";;
-n|--ods-namespace) ODS_NAMESPACE="$2"; shift;;

-i=*|--ods-image-tag=*) ODS_IMAGE_TAG="${1#*=}";;
-i|--ods-image-tag) ODS_IMAGE_TAG="$2"; shift;;

-m=*|--bitbucket-ods-project=*) ODS_BITBUCKET_PROJECT="${1#*=}";;
-m|--bitbucket-ods-project) ODS_BITBUCKET_PROJECT="$2"; shift;;

-p=*|--project=*) PROJECT="${1#*=}";;
-p|--project) PROJECT="$2"; shift;;

-q=*|--quickstarter-repository=*) QuickstarterRepository="${1#*=}";;
-q|--quickstarter-repository) QuickstarterRepository="$2"; shift;;

-s=*|--sonar-quality-profile=*) SONAR_QUALITY_PROFILE="${1#*=}";;
-s|--sonar-quality-profile) SONAR_QUALITY_PROFILE="$2"; shift;;

*) echo "Unknown parameter passed: $1"; exit 1;;
esac; shift; done

# echo "create trigger secret"
# SECRET=$(head /dev/urandom | tr -dc A-Za-z0-9 | head -c 13 ; echo '')

tailor --namespace=${PROJECT}-cd --non-interactive \
apply \
--param=ODS_GIT_REF=${ODS_GIT_REF} \
--param=PROJECT=${PROJECT} \
--param=BITBUCKET_URL=${BITBUCKET_URL} \
--param=ODS_NAMESPACE=${ODS_NAMESPACE} \
--param=ODS_IMAGE_TAG=${ODS_IMAGE_TAG} \
--param=ODS_BITBUCKET_PROJECT=${ODS_BITBUCKET_PROJECT} \
--param=SONAR_QUALITY_PROFILE="${SONAR_QUALITY_PROFILE}" \
--param=QuickstarterRepository=${QuickstarterRepository} \
--selector template=golden-test-pipeline

0 comments on commit b7dd84e

Please sign in to comment.