Last active
August 9, 2020 07:47
-
-
Save ShapeShifter499/1c0e0afde5c0209813f198bae0b29ca2 to your computer and use it in GitHub Desktop.
h930 pipeline for jenkins
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pipeline { | |
agent any | |
environment { | |
DEVICE = "h930" | |
DEVICE_BLOBS = "oreo-blobs" | |
DEVICE_MANIFEST = "https://raw.githubusercontent.com/ShapeShifter499/LG_v30-LineageOS_Manifest/lineage-16.0/lg_v30-${DEVICE}.xml" | |
SOURCE_TREE = "$JENKINS_HOME/workspace/LineageOS/lineageos_code_sync" | |
CCACHE_DIR = "$JENKINS_HOME/../.ccache" | |
BRANCHNAME = "lineage-16.0" | |
BUILDNAME = "lineage-16.0" | |
BUILD_TYPE = "userdebug" | |
REPO_BIN = "$JENKINS_HOME/../bin/repo" | |
GIT_RELEASE_SCRIPT = "$JENKINS_HOME/../bin/git-upload-releases.sh" | |
JAVA_HOME = "/usr/lib/jvm/java-11-openjdk-amd64/" | |
ANDROID_JAVA_HOME = "/usr/lib/jvm/java-11-openjdk-amd64/" | |
TMPDIR = "$WORKSPACE/$DEVICE-tmp-dir" | |
GIT_user_name = "ShapeShifter499" | |
GIT_user_email = "gero3977@gmail.com" | |
GIT_release_repo_name = "LG_v30-LineageOS_Manifest" | |
GIT_TAG = "\$(basename -s .zip.md5sum $BUILDNAME*.zip.md5sum | cut -d- -f 1-3,5)" | |
} | |
stages { | |
stage('Sync'){ | |
steps { | |
sh '''#!/bin/bash | |
mkdir -p $DEVICE-build | |
mkdir -p $TMPDIR | |
cd $DEVICE-build | |
if [ -d .repo ]; then | |
echo "Inital sync already done" | |
echo "Making sure code is up to date before continuing" | |
wget $DEVICE_MANIFEST -O .repo/local_manifests/$DEVICE.xml | |
$REPO_BIN sync | |
else | |
echo "Making inital synchronization of LineageOS code" | |
$REPO_BIN init -u git://www.github.com/LineageOS/android.git -b $BRANCHNAME --reference=$SOURCE_TREE | |
mkdir -p .repo/local_manifests | |
wget $DEVICE_MANIFEST -O .repo/local_manifests/$DEVICE.xml | |
$REPO_BIN sync | |
fi | |
git config --global user.name $GIT_user_name | |
git config --global user.email $GIT_user_email | |
''' | |
} | |
} | |
stage('Build Locking'){ | |
steps { | |
sh '''#!/bin/bash | |
echo "Checking if a build lock file exists before starting a build." | |
while [ -f $jenkins_building_lock_file ]; do | |
echo "" | |
echo "Found a build lock file. This means another job is compiling." | |
echo "Lets wait till no jobs are compiling anything before continuing" | |
echo "Checking again in five minutes" | |
sleep 300s | |
echo "" | |
done | |
echo "" | |
echo "No build lock file found." | |
echo "Lets create one now to keep other jobs from hogging resources." | |
echo "" | |
touch $jenkins_building_lock_file | |
''' | |
} | |
} | |
stage('Clean'){ | |
steps { | |
sh '''#!/bin/bash | |
PATH="$JAVA_HOME/bin:$JAVA_HOME/jre/bin:$PATH" | |
export PATH | |
rm -rf $DEVICE-output | |
rm -rf $TMPDIR | |
mkdir -p $TMPDIR | |
cd $DEVICE-build | |
source build/envsetup.sh | |
make clean | |
mka clobber | |
''' | |
} | |
} | |
stage('Build'){ | |
steps { | |
sh '''#!/bin/bash +e | |
PATH="$JAVA_HOME/bin:$JAVA_HOME/jre/bin:$PATH" | |
export PATH | |
cd $DEVICE-build | |
source build/envsetup.sh | |
export USE_CCACHE=1 | |
ccache -M 1024G | |
export LC_ALL=C | |
lunch lineage_$DEVICE-$BUILD_TYPE | |
mka bacon installed-file-list | |
''' | |
} | |
} | |
stage('Clear Build Locking'){ | |
steps { | |
sh '''#!/bin/bash | |
echo "If you read this, all the compiling is done for this job!" | |
echo "Better check if there were any errors" | |
echo "Lets remove the build lock file we created earlier so another job can start compiling." | |
if [ -f $jenkins_building_lock_file ]; then | |
echo "" | |
rm $jenkins_building_lock_file | |
echo "" | |
fi | |
''' | |
} | |
} | |
stage('Upload to Jenkins'){ | |
steps { | |
sh '''#!/bin/bash +e | |
mkdir -p $DEVICE-output | |
cp $DEVICE-build/out/target/product/$DEVICE/$BUILDNAME-* $DEVICE-output | |
cp $DEVICE-build/out/target/product/$DEVICE/installed-files.txt $DEVICE-output | |
cp $DEVICE-build/.repo/local_manifests/$DEVICE.xml $DEVICE-output/$DEVICE-manifest.xml | |
''' | |
archiveArtifacts artifacts: '*-output/*', fingerprint: true | |
} | |
} | |
stage('Upload to GitHub'){ | |
steps { | |
withCredentials([string(credentialsId: '<REDACTED>', variable: 'GIT_TOKEN')]) { | |
sh '''#!/bin/bash | |
$GIT_RELEASE_SCRIPT | |
''' | |
} | |
} | |
} | |
} | |
post { | |
unsuccessful { | |
sh '''#!/bin/bash | |
echo "If you read this, this job has failed or was aborted!" | |
echo "Better double check if everything is alright." | |
echo "Lets remove the build lock file we created earlier so another job can start compiling." | |
if [ -f $jenkins_building_lock_file ]; then | |
echo "" | |
rm $jenkins_building_lock_file | |
echo "" | |
fi | |
''' | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment