From 4e9a628549e60454e2f6791a3ff494df0055fde1 Mon Sep 17 00:00:00 2001 From: peri4 Date: Wed, 15 Nov 2023 18:48:30 +0300 Subject: [PATCH] initial commit --- README.md | 70 ++++++++++++++++++++++++++++++++++++++++++ src/org/SHS/SDK.groovy | 34 ++++++++++++++++++++ vars/SHS.txt | 1 + 3 files changed, 105 insertions(+) create mode 100644 README.md create mode 100644 src/org/SHS/SDK.groovy create mode 100644 vars/SHS.txt diff --git a/README.md b/README.md new file mode 100644 index 0000000..c17e684 --- /dev/null +++ b/README.md @@ -0,0 +1,70 @@ +# Helper class for Jenkins + +This repo add functionality for automate building with `platforms.json` configuration. + +## Setup + +You should add `PLATFORMS_GIT` environment to your Jenkins with url to git repo, which +contains single `platforms.json` file. + +Next you should register this library in Jenkins -> System settings -> Global Pipeline Libraries: +* Library name: `SHS.Platforms` +* Default version: `master` +* Project Repository: `https://git.shs.tools/SHS/jenkins_lib.git` + +## API + +`org.SHS.Platforms` Class: + * `get()` - download and parse `platforms.json` file from `PLATFORMS_GIT` + * `root()` - returns root JSON object of `platforms.json` + * `forEach(func, ...)` - iterate over platforms, `func` is only mandatory parameter: + * `func` - method to execute for each enabled platform, pass JSON element of current platform and optional CMake toolchain argument + * `stagePrefix` - prefix string for `stage` + * `stageSuffix` - suffix string for `stage` + * `whiteList` - array of permitted names, ignored if empty + * `blackList` - array of denied names, ignored if empty + +`whiteList` and `blackList` are case-insensitive, and can be part of platform name + +## Usage + +Simple: +``` +@Library('SHS.Platforms') _ +node { + def pl = new org.SHS.Platforms(this) + pl.get() + pl.forEach ({ dist -> + print("works in ${dist.docker_image}") + }) +} +``` + +With toolchain: +``` +@Library('SHS.Platforms') _ +node { + def pl = new org.SHS.Platforms(this) + pl.get() + pl.forEach ({ dist, cmake_toolchain -> + print("compile in ${dist.docker_image} with arg ${cmake_toolchain}") + }) +} +``` + +With filter: +``` +@Library('SHS.Platforms') _ +node { + def pl = new org.SHS.Platforms(this) + pl.get() + pl.forEach ({ dist -> + print("works in ${dist.docker_image}") + }, + stagePrefix: "Build ", + stageSuffix: " soft", + whiteList: ["ubuntu", "debian", "osx"], + blackList: ["20.04", "11"] + ) +} +``` diff --git a/src/org/SHS/SDK.groovy b/src/org/SHS/SDK.groovy new file mode 100644 index 0000000..35f5710 --- /dev/null +++ b/src/org/SHS/SDK.groovy @@ -0,0 +1,34 @@ +package org.SHS + +@Library('SHS.Platforms') _ +class SDK { + def steps + def pl + + public SDK(steps) { + this.steps = steps + this.pl = new org.SHS.Platforms(this.steps) + } + + public void build() { + steps.stage("Download sources") { + steps.checkout scm + } + //pl.get() + pl._root = steps.readJSON(file: '${env.SHSSDK_DIR}/platforms.json') + pl.forEach ({ dist, cmake_toolchain -> + print("compile in ${dist.docker_image} with arg ${cmake_toolchain}") + /*steps.docker.image("${dist.docker_image}-shssdk").inside() { + steps.sh "rm -rf ./release" + steps.sh "mkdir -p build" + steps.sh "cd build && rm -rf ./* && cmake -G Ninja ${toolchain} -DBUILD_NUMBER=${env.BUILD_NUMBER} -DCMAKE_INSTALL_PREFIX=../release ../src" + steps.sh "cd build && cmake --build ./ --target install -j${env.JOBS_COUNT}" + steps.archiveArtifacts 'release/*/*/*' + steps.sh 'rm -rf ./build ./bin ./release ./builds' + }, + //whiteList: ["ubuntu", "debian", "osx"], + blackList: ["android"]*/ + ) + } + +} diff --git a/vars/SHS.txt b/vars/SHS.txt new file mode 100644 index 0000000..4483ec3 --- /dev/null +++ b/vars/SHS.txt @@ -0,0 +1 @@ +libraryVersion = '0.0.1'