120 lines
5.1 KiB
Groovy
120 lines
5.1 KiB
Groovy
pipeline {
|
|
agent any
|
|
parameters {
|
|
string(name: 'version', defaultValue: '', description: 'specify version manually')
|
|
booleanParam(name: "use_github", defaultValue: true, description: "use github repos")
|
|
booleanParam(name: "publish", defaultValue: true, description: "publish new builds to gitea")
|
|
}
|
|
options {
|
|
timestamps()
|
|
ansiColor("xterm-256color")
|
|
disableConcurrentBuilds()
|
|
buildDiscarder(logRotator(daysToKeepStr: '30', numToKeepStr: '10', artifactNumToKeepStr: '1'))
|
|
}
|
|
triggers {
|
|
parameterizedCron('@monthly %publish=true,build_web=true,web_ws_url=true')
|
|
}
|
|
environment {
|
|
GITEA_URL = "git.sudo.is"
|
|
GIT_CONFIG_PARAMETERS = "'color.ui=always' 'advice.detachedHead=false'"
|
|
HASS_USE_GITHUB = params.use_github.toString()
|
|
HASS_PUBLISH = params.publish.toString()
|
|
HASS_MAIN_BRANCH = "dev"
|
|
}
|
|
stages {
|
|
stage('checkout') {
|
|
steps {
|
|
// this stage does the same as build/init-git.sh, but in Jenkins it makes sense to let Jenkins handle git with its git-functions instead of a shell script
|
|
script {
|
|
env.GITEA_USER = sh(script: "echo $GIT_URL | cut -d'/' -f4", returnStdout: true).trim()
|
|
|
|
env.HASS_GIT_URL = params.use_github ? "https://github.com/home-assistant/core" : "https://git.sudo.is/home-assistant/core"
|
|
dir('core') {
|
|
git(url: env.HASS_GIT_URL, branch: env.HASS_MAIN_BRANCH)
|
|
if (params.version != "") {
|
|
env.HASS_VERSION = params.version
|
|
}
|
|
else {
|
|
sh("git fetch --tags")
|
|
env.HASS_VERSION = sh(script: "${env.WORKSPACE}/.pipeline/version.sh", returnStdout: true).trim()
|
|
}
|
|
sh "git checkout ${env.HASS_VERSION}"
|
|
//sh "git checkout dev"
|
|
}
|
|
currentBuild.displayName += " - ${env.HASS_VERSION}"
|
|
currentBuild.description = env.HASS_VERSION
|
|
writeFile(file: "dist/hass_version.txt", text: env.HASS_VERSION)
|
|
}
|
|
sh "ls --color=always -l"
|
|
sh "env | grep --color=always hass"
|
|
}
|
|
}
|
|
stage('upstream container') {
|
|
when {
|
|
branch "main"
|
|
}
|
|
steps {
|
|
script {
|
|
dir('upstream-container') {
|
|
sh "docker build -t git.sudo.is/ben/hass-upstream:latest ."
|
|
if (params.publish == true) {
|
|
sh "docker tag git.sudo.is/ben/hass-upstream:latest git.sudo.is/ben/hass-upstream:${env.HASS_VERSION}"
|
|
sh "docker push git.sudo.is/ben/hass-upstream:latest"
|
|
sh "docker push git.sudo.is/ben/hass-upstream:${env.HASS_VERSION}"
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
stage('build hass') {
|
|
steps {
|
|
sh ".pipeline/build.sh"
|
|
//script {
|
|
// env.HASS_SERVER_DEB = sh(script: ".pipeline/echo-hass-deb.sh", returnStdout: true).trim()
|
|
//}
|
|
//echo "hass: ${env.HASS_DEB}"
|
|
}
|
|
}
|
|
}
|
|
post {
|
|
always {
|
|
sh "env | grep hass"
|
|
sh "sha256sum core/requirements_all.txt core/requirements.txt"
|
|
}
|
|
success {
|
|
sh "ls --color=always -1 . ./dist/"
|
|
sh "docker push git.sudo.is/ben/hass:${env.HASS_VERSION}"
|
|
archiveArtifacts(artifacts: "dist/*.tar.gz,dist/*.deb,dist/*.zip,dist/hass_version.txt,dist/sha256sums.txt", fingerprint: true)
|
|
script {
|
|
if (fileExists("build/publish.sh") && params.publish == true) {
|
|
withCredentials([string(credentialsId: "gitea-user-${env.GITEA_USER}-full-token", variable: 'GITEA_SECRET')]) {
|
|
sh "build/publish.sh"
|
|
}
|
|
//sh "cp -v dist/${deb} ${env.JENKINS_HOME}/artifacts"
|
|
//build(
|
|
// job: "/utils/apt",
|
|
// wait: true,
|
|
// propagate: true,
|
|
// parameters: [[
|
|
// $class: 'StringParameterValue',
|
|
// name: 'filename',
|
|
// value: deb
|
|
// ]]
|
|
//)
|
|
}
|
|
}
|
|
}
|
|
cleanup {
|
|
dir('core') {
|
|
deleteDir()
|
|
}
|
|
cleanWs(deleteDirs: true, disableDeferredWipeout: true, notFailBuild: true)
|
|
sh "docker container rm hass-build || true"
|
|
//sh "docker iamge rm hass-builder:${HASS_VERSION} || true"
|
|
//xh "docker image rm hass:${HASS_VERSION} || true"
|
|
//sh "docker image rm ${GITEA_URL}/${GITEA_USER}/hass:${HASS_VERSION} || true"
|
|
//sh "docker image rm ${GITEA_URL}/${GITEA_USER}/hass:latest || true"
|
|
}
|
|
}
|
|
}
|