Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save ShapeShifter499/9750a0d5edf860f01ed203bab13e7684 to your computer and use it in GitHub Desktop.
Save ShapeShifter499/9750a0d5edf860f01ed203bab13e7684 to your computer and use it in GitHub Desktop.
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 = "/media/shapeshifter499/compile-disk/jenkins/workspace/LineageOS/lineageos_code_sync"
CCACHE_DIR = "/media/shapeshifter499/compile-disk/.ccache"
BRANCHNAME = "lineage-16.0"
BUILDNAME = "lineage-16.0"
BUILD_TYPE = "userdebug"
REPO_BIN = "/media/shapeshifter499/compile-disk/bin/repo"
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_TOKEN = credentials('<REDACTED>')
}
stages {
stage('Sync') {
steps {
sh '''#!/bin/bash
mkdir -p $DEVICE-build
cd $DEVICE-build
printenv
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 forall -c "git reset --hard";
$REPO_BIN forall -c "git clean -f -d";
$REPO_BIN sync -d -c --force-sync;
else
echo "Making inital synchronization of LineageOS code";
$REPO_BIN init -u http://www.github.com/LineageOS/android -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
exit 0
'''
}
}
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 DATETIME=$(date -u +%Y%m%d_%H%M%S)
export LC_ALL=C
lunch lineage_$DEVICE-$BUILD_TYPE
mka bacon installed-file-list
'''
}
}
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 {
sh '''#!/bin/bash
cd $DEVICE-output
GIT_release_repo_name="LG_v30-LineageOS_Manifest"
GIT_TAG="$(basename -s .zip.md5sum $BUILDNAME*.zip.md5sum | cut -d- -f 1-3,5)"
# Create a release
release=$(curl -XPOST -H "Authorization:token $GIT_TOKEN" --data "{\"tag_name\": \"${GIT_TAG}_${DEVICE_BLOBS}\", \"target_commitish\": \"$BRANCHNAME\", \"name\": \"${GIT_TAG}_${DEVICE_BLOBS}\", \"draft\": false, \"prerelease\": false}" https://api.github.com/repos/$GIT_user_name/$GIT_release_repo_name/releases)
# Extract the id of the release from the creation response
id=$(echo "$release" | sed -n -e 's/"id":\\ \\([0-9]\\+\\),/\\1/p' | head -n 1 | sed 's/[[:blank:]]//g')
# Upload the artifact
for ARTIFACT in `find . -maxdepth 1 -type f -print | sed 's/^\\.\\///'`
do
file_artifact=$(curl -XPOST -H "Authorization:token $GIT_TOKEN" -H "Content-Type:application/octet-stream" --data-binary @$ARTIFACT https://uploads.github.com/repos/$GIT_user_name/$GIT_release_repo_name/releases/$id/assets?name=$ARTIFACT)
echo "Uploading $ARTIFACT to GitHub"
$file_artifact
done
'''
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment