Skip to content

Commit

Permalink
Add common function for uploads
Browse files Browse the repository at this point in the history
  • Loading branch information
steelhead31 committed Oct 4, 2023
1 parent ed57530 commit fbb11e6
Showing 1 changed file with 49 additions and 81 deletions.
130 changes: 49 additions & 81 deletions linux/Jenkinsfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

/*
--------------------------------------------
buildArch RPM DEB Comments
Expand Down Expand Up @@ -153,6 +154,44 @@ private String getCurrentBranch() {
return scm.branches.first().name ?: 'master'
}

// Define Generic Test & Upload Function
def CheckAndUpload(String Target, String Distro, String BuildArch, String Version, String DistroList, String Value, String PackageDir, String Key) {
echo "Entering Check & Upload"
// Set Env Vars For Debs & Rpms
env.BUILDARCH = BuildArch
env.VERSION = Version
env.DISTROLIST = DistroList
env.VALUE = Value
env.PACKAGEDIR = PackageDir
env.KEY = Key
try {
def ResponseCode = sh(script: "curl -o /dev/null --silent --head --write-out '%{http_code}' ${Target}.123", returnStdout: true).trim()
echo "ResponseCode = ${ResponseCode}"
if ( ResponseCode == '200') {
echo "Target Exists - Skipping"
} else {
echo "Target Doesnt Exist - Upload Files"
switch(Distro) {
case "Debian":
jf 'rt u **/build/ospackage/temurin-*${BUILDARCH}.deb deb/pool/main/t/temurin-${VERSION}/ --target-props=${DISTROLIST}deb.component=main;deb.architecture=${BUILDARCH} --flat=true'
break
case "Alpine":
jf 'rt u **/build/ospackage/temurin-*j*.apk apk/alpine/main/${BUILDARCH}/ --flat=true'
break
case "RPMS":
jf 'rt u **/build/ospackage/*.${VALUE}.rpm ${PACKAGEDIR}/${KEY}/Packages/ --flat=true'
break
default:
echo "Default Case"
jf 'rt u **/build/ospackage/*.${VALUE}.rpm ${PACKAGEDIR}/${KEY}/Packages/ --flat=true'
break
}
}
} catch (Exception e) {
error "Error While Checking URL ${Target}: ${e.message}"
}
}

// function only handle debian as DISTRO
def jenkinsStepDeb() {
def temurinVersion = "${TYPE.toLowerCase()} ${VERSION} - ${ARCH}"
Expand Down Expand Up @@ -287,60 +326,22 @@ def uploadAlpineArtifacts(String buildArch) {
// set BUILDARCH environment variable for ${buildArch}
env.BUILDARCH = buildArch


def Distro = "Alpine"
def PackFiles = findFiles(glob: '**/build/ospackage/temurin-*j*.apk') // List All Packages To Upload
def SrcFiles = findFiles(glob: '**/build/ospackage/temurin-*src*.apk') // List All Sources To Upload
def AllFiles = PackFiles + SrcFiles

for (PackFile in PackFiles) {

for (PackFile in AllFiles) {
def FileName = PackFile.name
def Target = "https://adoptium.jfrog.io/artifactory/apk/alpine/main/${BUILDARCH}/${FileName}"

echo "File : ${PackFile}"
echo "Filename : ${FileName}"
echo "Target : ${Target}"

try {
def ResponseCode = sh(script: "curl -o /dev/null --silent --head --write-out '%{http_code}' ${Target}", returnStdout: true).trim()
echo "ResponseCode = ${ResponseCode}"

if ( ResponseCode == '200') {
echo "Target Exists - Skipping"
} else {
echo "Target Doesnt Exist - Upload Files"
jf 'rt u **/build/ospackage/temurin-*j*.apk apk/alpine/main/${BUILDARCH}/ --flat=true'
}

} catch (Exception e) {
error "Error While Checking URL ${Target}: ${e.message}"
}
}

for (SrcFile in SrcFiles) {
def FileName = SrcFile.name
def Target = "https://adoptium.jfrog.io/artifactory/apk/alpine/main/${BUILDARCH}/${FileName}"

echo "File : ${SrcFile}"
echo "Filename : ${FileName}"
echo "Target : ${Target}"

try {
def ResponseCode = sh(script: "curl -o /dev/null --silent --head --write-out '%{http_code}' ${Target}", returnStdout: true).trim()
echo "ResponseCode = ${ResponseCode}"

if ( ResponseCode == '200') {
echo "Target Exists - Skipping"
} else {
echo "Target Doesnt Exist - Upload Files"
jf 'rt u **/build/ospackage/temurin-*src*.apk apk/alpine/main/${BUILDARCH}/ --flat=true'
}
} catch (Exception e) {
error "Error While Checking URL ${Target}: ${e.message}"
}
CheckAndUpload(Target, Distro, buildArch, '', '', '', '', '' )
}
// unset BUILDARCH environment variable
}

def uploadDebArtifacts(String buildArch) {
def Distro = "Debian"
def debArchList = [
'x86_64' : 'amd64',
'armv7l': 'armhf',
Expand Down Expand Up @@ -393,30 +394,15 @@ def uploadDebArtifacts(String buildArch) {
def FileName = PackFile.name
def Target = "https://adoptium.jfrog.io/artifactory/deb/pool/main/t/temurin-${VERSION}/${FileName}"

echo "File : ${PackFile}"
echo "Filename : ${FileName}"
echo "Target : ${Target}"

try {
def ResponseCode = sh(script: "curl -o /dev/null --silent --head --write-out '%{http_code}' ${Target}", returnStdout: true).trim()
echo "ResponseCode = ${ResponseCode}"

if ( ResponseCode == '200') {
echo "Target Exists - Skipping"
} else {
echo "Target Doesnt Exist - Upload Files"
jf 'rt u **/build/ospackage/temurin-*${BUILDARCH}.deb deb/pool/main/t/temurin-${VERSION}/ --target-props=${DISTROLIST}deb.component=main;deb.architecture=${BUILDARCH} --flat=true'
}
} catch (Exception e) {
error "Error While Checking URL ${Target}: ${e.message}"
}
CheckAndUpload(Target, Distro, BUILDARCH, VERSION, DISTROLIST, '', '', '' )
}
}
break
}
}

def uploadRpmArtifacts(String DISTRO, String rpmArch) {
def Distro = "RPM"
def distro_Package = [
'redhat' : [
'rpm/centos/7',
Expand Down Expand Up @@ -487,29 +473,11 @@ def uploadRpmArtifacts(String DISTRO, String rpmArch) {
def FileName = PackFile.name
def Target = "https://adoptium.jfrog.io/artifactory/${PACKAGEDIR}/${KEY}/Packages/${FileName}"

echo "File : ${PackFile}"
echo "Filename : ${FileName}"
echo "Target : ${Target}"

try {
def ResponseCode = sh(script: "curl -o /dev/null --silent --head --write-out '%{http_code}' ${Target}", returnStdout: true).trim()
echo "ResponseCode = ${ResponseCode}"

if ( ResponseCode == '200') {
echo "Target Exists - Skipping"
} else {
echo "Target Doesnt Exist - Upload Files"
jf 'rt u **/build/ospackage/*.${VALUE}.rpm ${PACKAGEDIR}/${KEY}/Packages/ --flat=true'
}

} catch (Exception e) {
error "Error While Checking URL ${Target}: ${e.message}"
}

CheckAndUpload(Target, Distro, rpmArchList.each, '', '', VALUE , PACKAGEDIR, KEY )
}
break
}
}
}
}
}
}

0 comments on commit fbb11e6

Please sign in to comment.