no env, more complex API to download/filter
This commit is contained in:
60
README.md
60
README.md
@@ -4,41 +4,57 @@ This repo add functionality for automate building with `platforms.json` configur
|
||||
|
||||
## Setup
|
||||
|
||||
You should add `PLATFORMS_GIT` and `PLATFORMS_FILTER_GIT` environment to your Jenkins with url to git repo, which
|
||||
contains single `platforms.json` and `filter.json` file.
|
||||
|
||||
`PLATFORMS_GIT` -> `platforms.json`
|
||||
|
||||
`PLATFORMS_FILTER_GIT` -> `filter.json`
|
||||
|
||||
|
||||
Next you should register this library in Jenkins -> System settings -> Global Pipeline Libraries:
|
||||
You should register this library in Jenkins -> System settings -> Global Pipeline Libraries:
|
||||
* Library name: `SHS.Platforms`
|
||||
* Default version: `master`
|
||||
* Project Repository: `https://git.shstk.ru/SHS/jenkins_lib.git`
|
||||
|
||||
|
||||
Then create pipeline job with fixed name `shstk-platforms` and set script to:
|
||||
```
|
||||
```js
|
||||
@Library('SHS.Platforms') _
|
||||
node {
|
||||
properties([copyArtifactPermission('*')])
|
||||
def pl = new org.SHS.Platforms(this)
|
||||
pl.createLocal()
|
||||
}
|
||||
```
|
||||
If you want to copy final json to host, add
|
||||
```
|
||||
|
||||
|
||||
// First download 'platforms.json' source file
|
||||
|
||||
// Download from 'https://git.shstk.ru/SHS/platforms.git'
|
||||
pl.download()
|
||||
|
||||
// OR
|
||||
|
||||
// Download from your git
|
||||
pl.download('https://my.git.address/my/repo.git')
|
||||
|
||||
|
||||
// Optionally filter with your lists
|
||||
pl.filter(whiteList: ['filter1', 'filter2'], blackList: ['filter3'])
|
||||
|
||||
|
||||
// Optionally mark platforms as 'ondemand' with your lists
|
||||
pl.setOndemand(whiteList: ['filter4', 'filter5'], blackList: ['filter6])
|
||||
|
||||
|
||||
// Compile JSON and save as artifact
|
||||
pl.create()
|
||||
|
||||
|
||||
// Optionally copy to your host location
|
||||
pl.copyToHost('/your/path/platforms.json')
|
||||
}
|
||||
```
|
||||
|
||||
## API
|
||||
|
||||
`org.SHS.Platforms` Class:
|
||||
* `createLocal()` - download and parse `platforms.json` from `PLATFORMS_GIT` and `filter.json` from `PLATFORMS_FILTER_GIT`, filter/prepare final JSON and save it to artifact
|
||||
* `copyToHost(path)` - call after createLocal() to copy final JSON to `path` on your host
|
||||
* `download()` - download `platforms.json` from 'https://git.shstk.ru/SHS/platforms.git' or custom git address
|
||||
* `filter()` - filter with white/black lists
|
||||
* `setOndemand()` - mark as 'ondemand' with white/black lists
|
||||
* `create()` - compile final JSON and save it to artifact
|
||||
* `copyToHost(path)` - copy final JSON to `path` on your host
|
||||
* `get()` - read and parse `platforms_local.json` file from "shstk-platforms" artifact
|
||||
* `root()` - returns root JSON object of `platforms.json`
|
||||
* `root()` - returns 'platforms' object of current platforms
|
||||
* `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`
|
||||
@@ -52,7 +68,7 @@ pl.copyToHost('/your/path/platforms.json')
|
||||
## Usage
|
||||
|
||||
Simple:
|
||||
```
|
||||
```js
|
||||
@Library('SHS.Platforms') _
|
||||
node {
|
||||
def pl = new org.SHS.Platforms(this)
|
||||
@@ -64,7 +80,7 @@ node {
|
||||
```
|
||||
|
||||
With toolchain:
|
||||
```
|
||||
```js
|
||||
@Library('SHS.Platforms') _
|
||||
node {
|
||||
def pl = new org.SHS.Platforms(this)
|
||||
@@ -76,7 +92,7 @@ node {
|
||||
```
|
||||
|
||||
With white/black lists:
|
||||
```
|
||||
```js
|
||||
@Library('SHS.Platforms') _
|
||||
node {
|
||||
def pl = new org.SHS.Platforms(this)
|
||||
|
||||
@@ -4,27 +4,29 @@ class Platforms {
|
||||
def steps
|
||||
def _root
|
||||
def _filter
|
||||
def _instructions
|
||||
|
||||
public Platforms(steps) {this.steps = steps}
|
||||
public Platforms(steps) {
|
||||
this.steps = steps
|
||||
_instructions = [:]
|
||||
}
|
||||
|
||||
public void get() {
|
||||
steps.stage("Read platforms_local.json") {
|
||||
steps.step([$class: 'CopyArtifact', projectName: 'shstk-platforms', target: 'platforms']);
|
||||
this._root = steps.readJSON(file: "platforms/platforms_local.json")
|
||||
/*if (steps.env.PLATFORMS_LOCAL_DIR == null) {
|
||||
steps.error "Add \"PLATFORMS_LOCAL_DIR\" node environment to local directory with write permission"
|
||||
}
|
||||
this._root = steps.readJSON(file: "${steps.env.PLATFORMS_LOCAL_DIR}/platforms_local.json")*/
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public def root() {return _root;}
|
||||
public def root() {return _root.platforms;}
|
||||
|
||||
public void forEach(Map args, functor) {
|
||||
def prefix = args.stagePrefix ?: ""
|
||||
def suffix = args.stageSuffix ?: ""
|
||||
def ondemand = args.ondemand ?: false
|
||||
filterJSON(args.whiteList ?: [], args.blackList ?: [], ondemand).each { key, dist ->
|
||||
filterJSON(args.whiteList ?: [], args.blackList ?: [], ondemand).platforms.each { key, dist ->
|
||||
if (dist.enabled) {
|
||||
def toolchain = dist.cmake_toolchain ?: ""
|
||||
if (toolchain != "") toolchain = "-DCMAKE_TOOLCHAIN_FILE=${toolchain}"
|
||||
steps.stage ("${prefix}${key}${suffix}") {
|
||||
@@ -32,52 +34,62 @@ class Platforms {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
public void forEach(functor) { forEach(functor, stagePrefix: "") }
|
||||
|
||||
public void createLocal() {
|
||||
if (steps.env.PLATFORMS_GIT == null) {
|
||||
steps.error "Add \"PLATFORMS_GIT\" node environment to git repo with \"platforms.json\" file (e.g. https://git.shstk.ru/SHS/platforms)"
|
||||
}
|
||||
if (steps.env.PLATFORMS_FILTER_GIT == null) {
|
||||
steps.error "Add \"PLATFORMS_FILTER_GIT\" node environment to git repo with \"filter.json\" file (e.g. https://git.shstk.ru/SHS/platforms-SHS)"
|
||||
}
|
||||
/*if (steps.env.PLATFORMS_LOCAL_DIR == null) {
|
||||
steps.error "Add \"PLATFORMS_LOCAL_DIR\" node environment to local directory with write permission"
|
||||
}*/
|
||||
public void download(git_url) {
|
||||
steps.dir("platforms_git") {
|
||||
steps.stage("Create platforms_local.json") {
|
||||
|
||||
steps.stage("Download platforms.json") {
|
||||
steps.deleteDir()
|
||||
steps.git url: "${steps.env.PLATFORMS_GIT}"
|
||||
this._root = steps.readJSON(file: 'platforms.json')
|
||||
|
||||
steps.deleteDir()
|
||||
steps.git url: "${steps.env.PLATFORMS_FILTER_GIT}"
|
||||
this._filter = steps.readJSON(file: 'filter.json')
|
||||
|
||||
steps.git url: git_url
|
||||
_root = steps.readJSON(file: 'platforms.json')
|
||||
if (_root.containsKey('install_instructions')) {
|
||||
_instructions = _root.install_instructions
|
||||
} else {
|
||||
_instructions = [:]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void download() {download('https://git.shstk.ru/SHS/platforms.git')}
|
||||
|
||||
public void filter(Map args) {
|
||||
def ret = [:]
|
||||
def iinst = [:]
|
||||
def wlist = []
|
||||
def blist = []
|
||||
ret.platforms = [:]
|
||||
if (this._root.containsKey('install_instructions')) {
|
||||
iinst = this._root.install_instructions
|
||||
_root.platforms.each({name, dist ->
|
||||
if (filterDist(name, dist, args.whiteList ?: [], args.blackList ?: [], true)) {
|
||||
ret.platforms[name] = dist
|
||||
ret.platforms[name]['enabled'] = true
|
||||
} else {
|
||||
ret.platforms[name] = [:]
|
||||
ret.platforms[name]['enabled'] = false
|
||||
}
|
||||
if (this._filter.containsKey('whiteList')) {
|
||||
wlist = this._filter.whiteList
|
||||
})
|
||||
_root = ret
|
||||
}
|
||||
if (this._filter.containsKey('blackList')) {
|
||||
blist = this._filter.blackList
|
||||
|
||||
public void setOndemand(Map args) {
|
||||
_root.platforms.each({name, dist ->
|
||||
if (dist.enabled) {
|
||||
if (filterDist(name, dist, args.whiteList ?: [], args.blackList ?: [], true)) {
|
||||
dist['ondemand'] = true
|
||||
} else {
|
||||
dist['ondemand'] = false
|
||||
}
|
||||
//_root.platforms[name] = dist
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
public void create() {
|
||||
def ret = [:]
|
||||
ret.platforms = [:]
|
||||
this._root.platforms.each({name, dist ->
|
||||
if (filterDist(name, dist, wlist, blist, true)) {
|
||||
// steps.print "${name} filter ok"
|
||||
if (dist.containsKey('ppa')) {
|
||||
if (dist.ppa.containsKey('install_instructions')) {
|
||||
if (dist.ppa.install_instructions instanceof String) {
|
||||
dist.ppa.install_instructions = iinst[dist.ppa.install_instructions]
|
||||
dist.ppa.install_instructions = _instructions[dist.ppa.install_instructions]
|
||||
if (dist.ppa.install_instructions == null) {
|
||||
steps.error "Invalid \"ppa.install_instructions\" reference for \"${name}\""
|
||||
}
|
||||
@@ -86,14 +98,10 @@ class Platforms {
|
||||
}
|
||||
}
|
||||
ret.platforms[name] = dist
|
||||
} else {
|
||||
// steps.print "${name} filter fail"
|
||||
}
|
||||
})
|
||||
steps.writeJSON(file: "platforms_local.json", json: ret, pretty: 2)
|
||||
steps.archiveArtifacts("platforms_local.json")
|
||||
this._root = ret
|
||||
// steps.writeJSON(file: "${steps.env.PLATFORMS_LOCAL_DIR}/platforms_local.json", json: ret, pretty: 2)
|
||||
}
|
||||
|
||||
public void copyToHost(path) {
|
||||
@@ -103,9 +111,6 @@ class Platforms {
|
||||
|
||||
//@NonCPS
|
||||
private Boolean filterDist(name, dist, whiteList, blackList, ondemand) {
|
||||
if (!dist.enabled) {
|
||||
return false;
|
||||
}
|
||||
def in_white = true, in_black = false
|
||||
if (dist.containsKey('ondemand'))
|
||||
in_white = !dist.ondemand
|
||||
@@ -121,9 +126,11 @@ class Platforms {
|
||||
|
||||
private def filterJSON(whiteList, blackList, ondemand) {
|
||||
def ret = [:]
|
||||
ret.platforms = [:]
|
||||
_root.platforms.each({name, dist ->
|
||||
if (filterDist(name, dist, whiteList, blackList, ondemand))
|
||||
ret[name] = dist
|
||||
if (filterDist(name, dist, whiteList, blackList, ondemand)) {
|
||||
ret.platforms[name] = dist
|
||||
}
|
||||
})
|
||||
return ret
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user