Skip to content

Commit

Permalink
Use declarative pipeline
Browse files Browse the repository at this point in the history
  • Loading branch information
ayufan committed May 1, 2017
1 parent d394b36 commit e00164e
Showing 1 changed file with 90 additions and 75 deletions.
165 changes: 90 additions & 75 deletions Jenkinsfile
Original file line number Diff line number Diff line change
@@ -1,87 +1,102 @@
/**
properties([
parameters([
string(defaultValue: '1.0', description: 'Current version number', name: 'VERSION'),
text(defaultValue: '', description: 'A list of changes', name: 'CHANGES'),
booleanParam(defaultValue: false, description: 'If build should be marked as pre-release', name: 'PRERELEASE'),
string(defaultValue: 'ayufan-pine64', description: 'GitHub username or organization', name: 'GITHUB_USER'),
string(defaultValue: 'build-pine64-image', description: 'GitHub repository', name: 'GITHUB_REPO'),
])
])
*/
pipeline {
// parameters {
// string (
// defaultValue: '1.0',
// description: 'Current version number',
// name : 'VERSION')
// text (
// defaultValue: '',
// description: 'A list of changes',
// name : 'CHANGES')
// booleanParam (
// defaultValue: false,
// description: 'If build should be marked as pre-release',
// name : 'PRERELEASE')
// string (
// defaultValue: '1.0',
// description: 'GitHub username or organization',
// name : 'GITHUB_USER')
// string (
// defaultValue: '1.0',
// description: 'GitHub repository',
// name : 'GITHUB_REPO')
// }

node('docker && linux-build') {
timestamps {
wrap([$class: 'AnsiColorBuildWrapper', colorMapName: 'xterm']) {
stage "Environment"
checkout scm
agent {
dockerfile {
dir 'build-environment'
label 'docker && linux-build'
args '--privileged -u 0:0'
}
}
environment {
USE_CCACHE = 'true'
RELEASE_NAME = "$RELEASE_NAME"
RELEASE = "$BUILD_NUMBER"
CCACHE_DIR = "$WORKSPACE/ccache"
PRERELEASE = "$PRERELEASE"
GITHUB_USER = "$GITHUB_USER"
GITHUB_REPO = "$GITHUB_REPO"
}
options {
timestamps()
}

def environment = docker.build('build-environment:build-pine64-image', 'build-environment')
stages {
stage('Prepare') {
steps {
sh 'ccache -M 0 -F 0'
sh 'git clean -ffdx -e ccache'
}
}

stage('Build') {
steps {
sh 'make'
}
}

environment.inside("--privileged -u 0:0") {
withEnv([
"USE_CCACHE=true",
"RELEASE_NAME=$VERSION",
"RELEASE=$BUILD_NUMBER"
]) {
stage 'Prepare'
sh '''#!/bin/bash
set +xe
export CCACHE_DIR=$WORKSPACE/ccache
ccache -M 0 -F 0
git clean -ffdx -e ccache
'''
stage('Release') {
steps {
sh '''#!/bin/bash
set -xe
shopt -s nullglob
stage 'Build'
sh '''#!/bin/bash
set +xe
export CCACHE_DIR=$WORKSPACE/ccache
make
'''
}

withEnv([
"VERSION=$VERSION",
"CHANGES=$CHANGES",
"PRERELEASE=$PRERELEASE",
"GITHUB_USER=$GITHUB_USER",
"GITHUB_REPO=$GITHUB_REPO"
]) {
stage 'Release'
sh '''#!/bin/bash
set -xe
shopt -s nullglob
github-release release \
--tag "${VERSION}" \
--name "$VERSION: $BUILD_TAG" \
--description "${CHANGES}\n\n${BUILD_URL}" \
--draft
github-release release \
for file in *.xz *.deb; do
github-release upload \
--tag "${VERSION}" \
--name "$VERSION: $BUILD_TAG" \
--description "${CHANGES}\n\n${BUILD_URL}" \
--draft
for file in *.xz *.deb; do
github-release upload \
--tag "${VERSION}" \
--name "$(basename "$file")" \
--file "$file" &
done
--name "$(basename "$file")" \
--file "$file" &
done
wait
wait
if [[ "$PRERELEASE" == "true" ]]; then
github-release edit \
--tag "${VERSION}" \
--name "$VERSION: $BUILD_TAG" \
--description "${CHANGES}\n\n${BUILD_URL}" \
--pre-release
else
github-release edit \
--tag "${VERSION}" \
--name "$VERSION: $BUILD_TAG" \
--description "${CHANGES}\n\n${BUILD_URL}"
fi
'''
}
if [[ "$PRERELEASE" == "true" ]]; then
github-release edit \
--tag "${VERSION}" \
--name "$VERSION: $BUILD_TAG" \
--description "${CHANGES}\n\n${BUILD_URL}" \
--pre-release
else
github-release edit \
--tag "${VERSION}" \
--name "$VERSION: $BUILD_TAG" \
--description "${CHANGES}\n\n${BUILD_URL}"
fi
'''
}
}
}

post {
always {
sh 'git clean -ffdx -e ccache'
}
}
}

0 comments on commit e00164e

Please sign in to comment.