diff --git a/CHANGELOG.md b/CHANGELOG.md index 7e60f2d0..3eafa967 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +## [1.62.0](https://github.com/cloudogu/ces-build-lib/releases/tag/1.62.0) - 2023-01-30 +## Added +- Function lintDockerfile to lint docker files #96. +- Function shellCheck to lint shell scripts #96. + ## [1.61.0](https://github.com/cloudogu/ces-build-lib/releases/tag/1.61.0) - 2023-01-13 ### Added - Add output from `kubectl describe` in the summary of the k8s resources in k3d. #94 @@ -23,7 +28,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [1.59.0](https://github.com/cloudogu/ces-build-lib/releases/tag/1.59.0) - 2022-11-28 ### Added -- Function `collectAndArchiveLogs` to collect dogu and resource information to help debugging k3s Jenkins buils. #89 +- Function `collectAndArchiveLogs` to collect dogu and resource information to help debugging k3s Jenkins builds. #89 - Function `applyDoguResource(String doguName, String doguNamespace, String doguVersion)` to apply a custom dogu resource into the cluster. This effectively installs a dogu if it is available. #89 diff --git a/README.md b/README.md index 04bcec6d..9026abf9 100644 --- a/README.md +++ b/README.md @@ -1140,7 +1140,7 @@ Example: # Markdown -`Markdown` provides function regardig the `Markdown Files` from the projects docs directory +`Markdown` provides function regarding the `Markdown Files` from the projects docs directory ```groovy Markdown markdown = new Markdown(this) @@ -1151,6 +1151,23 @@ Example: running a container with the latest https://github.com/tcort/markdown-link-check image and verifies that the links in the defined project directory are alive +### DockerLint + +```groovy +lintDockerfile() // uses Dockerfile as default; optional parameter +``` + +See [lintDockerFile](vars/lintDockerfile.groovy) + +### ShellCheck + +```groovy +shellCheck() // search for all .sh files in folder and runs shellcheck +shellCheck(fileList) // fileList="a.sh b.sh" execute shellcheck on a custom list +``` + +See [shellCheck](vars/shellCheck.groovy) + # Steps ## mailIfStatusChanged diff --git a/pom.xml b/pom.xml index 05393be5..7c515c53 100644 --- a/pom.xml +++ b/pom.xml @@ -7,7 +7,7 @@ com.cloudogu.ces ces-build-lib ces-build-lib - 1.61.0 + 1.62.0 UTF-8 diff --git a/vars/lintDockerfile.groovy b/vars/lintDockerfile.groovy new file mode 100644 index 00000000..23b9bc52 --- /dev/null +++ b/vars/lintDockerfile.groovy @@ -0,0 +1,8 @@ +package com.cloudogu.ces.cesbuildlib + +def call(String dockerfile = "Dockerfile") { + // only latest version available + docker.image('projectatomic/dockerfile-lint:latest').inside({ + sh "dockerfile_lint -p -f ${dockerfile}" + }) +} diff --git a/vars/shellCheck.groovy b/vars/shellCheck.groovy new file mode 100644 index 00000000..02601b1b --- /dev/null +++ b/vars/shellCheck.groovy @@ -0,0 +1,35 @@ +/** + * shellcheck for jenkins-pipelines https://github.com/koalaman/shellcheck + * + */ +package com.cloudogu.ces.cesbuildlib + +/** + * run shellcheck with a custom fileList + * sample input "test1.sh", "test2.sh" + * + */ +def call(fileList) { + executeWithDocker(fileList) +} + +/** + * run shellcheck on every .sh file inside the project folder + * note: it ignores ./ecosystem folder for usage with ecosystem instances + * + */ +def call() { + def fileList = sh (script: 'find . -path ./ecosystem -prune -o -type f -regex .*\\.sh -print', returnStdout: true) + fileList='"' + fileList.trim().replaceAll('\n','" "') + '"' + executeWithDocker(fileList) +} + +/* +* run the alpine based shellcheck image +* note: we encountered some problems while using the minified docker image +*/ +private def executeWithDocker(fileList){ + docker.image('koalaman/shellcheck-alpine:stable').inside(){ + sh "/bin/shellcheck ${fileList}" + } +}