#!groovy def repository = "registry.c.test-chamber-13.lan" def repositoryCreds = "harbor-repository-creds" def shortCommit def workspace def dockerFile def label = "kubernetes-${UUID.randomUUID().toString()}" def templateName = "pipeline-worker" pipeline { agent { kubernetes { yaml functions.podYaml( repo: repository, templateName: templateName, kaniko: true, alpine: true, [ [ name: "sonar", path: "${repository}/library/sonarscanner:latest", command: "/bin/sh" ], [ name: "golang", path: "${repository}/dockerhub/library/golang:alpine", command: "/bin/sh" ] ] ) } } stages { stage('Clone Repository') { steps { script { checkout ([$class: "GitSCM", branches: scm.branches, extensions: scm.extensions + [$class: 'CloneOption', shallow: true], userRemoteConfigs: scm.userRemoteConfigs, ]) shortCommit = sh(returnStdout: true, script: "git log -n 1 --pretty=format:'%h'").trim() } } } stage ('Initalize Jenkins') { parallel { stage ('Set Workspace') { steps { script { workspace = pwd() dockerFile = """FROM registry.c.test-chamber-13.lan/dockerhub/library/golang:alpine AS builder COPY . /go/src/app WORKDIR /go/src/app RUN apk add --no-cache git && \\ git config --global --add safe.directory /go/src/app && \\ GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build -v -ldflags="-s -w" -tags timetzdata -o ifire ./ FROM registry.c.test-chamber-13.lan/library/alpine:latest LABEL org.opencontainers.image.title="Is the internet on fire?" RUN addgroup -S -g 1000 app && \\ adduser --disabled-password -G app --gecos "application account" --home "/home/app" --shell "/sbin/nologin" --uid 1000 app && \\ apk add --no-cache bind-tools COPY --from=builder --chown=app:app /go/src/app/ifire /usr/local/bin/ifire USER app:app WORKDIR /home/app ENTRYPOINT ["/bin/sh", "-c", "ifire"] """ } } } stage ('Prepare SonarScanner') { steps { script { def sonarScannerConfig = """ sonar.projectKey=${env.JOB_BASE_NAME.replace(" ", "-")} sonar.projectVersion=${shortCommit} sonar.sources=. sonar.exclusions=**/*_test.go,**/vendor/**,**/testdata/*,html/** sonar.tests=. sonar.test.inclusions=**/*_test.go sonar.test.exclusions=**/vendor/** sonar.go.coverage.reportPaths=cover.out """ writeFile file: 'sonar-project.properties', text: sonarScannerConfig } } } } } } }