diff --git a/src/pipeline/common/Manifest.groovy b/src/pipeline/common/Manifest.groovy new file mode 100644 index 0000000..ccb36e9 --- /dev/null +++ b/src/pipeline/common/Manifest.groovy @@ -0,0 +1,46 @@ +package pipeline.common +import java.io.File; + +def downloadManifest(String url, String target){ + withCredentials([ + usernamePassword(credentialsId: 'a94afe79-82f5-495a-877c-183567c51e0b', + passwordVariable: 'BINTRAY_API_KEY', + usernameVariable: 'BINTRAY_USERNAME') + ]){ + sh 'curl --user $BINTRAY_USERNAME:$BINTRAY_API_KEY --retry 5 --retry-delay 5 ' + "$url" + ' -o ' + "${target}" + } +} + +def stashManifest(String manifest_name, String manifest_path){ + stash name: "$manifest_name", includes: "$manifest_path" + manifest_dict = [:] + manifest_dict["stash_name"] = "manifest_name" + manifest_dict["stash_path"] = "manifest_path" + return manifest_dict +} + +def unstashManifest(Map manifest_dict, String target_dir){ + String manifest_name = manifest_dict["stash_name"] + String manifest_path = manifest_dict["stash_path"] + dir(target_dir){ + unstash "$manifest_name" + } + manifest_path = target_dir + File.separator + manifest_path + return manifest_path +} + +def checkoutTargetRepo(String manifest_path, String repo_name, String on_build_config_dir){ + sh """#!/bin/bash -ex + pushd $on_build_config_dir + ./build-release-tools/HWIMO-BUILD ./build-release-tools/application/reprove.py \ + --manifest ${manifest_path} \ + --builddir ${WORKSPACE}/build-deps \ + --jobs 8 \ + --force \ + checkout \ + packagerefs + + """ + String repo_dir = "${WORKSPACE}/build-deps/$repo_name" + return repo_dir +} diff --git a/src/pipeline/common/ShareMethod.groovy b/src/pipeline/common/ShareMethod.groovy new file mode 100644 index 0000000..a2f00b5 --- /dev/null +++ b/src/pipeline/common/ShareMethod.groovy @@ -0,0 +1,67 @@ +package pipeline.common + +def checkout(String url, String branch, String targetDir){ + checkout( + [$class: 'GitSCM', branches: [[name: branch]], + extensions: [[$class: 'RelativeTargetDirectory', relativeTargetDir: targetDir]], + userRemoteConfigs: [[url: url]]]) +} +def checkout(String url, String branch){ + checkout( + [$class: 'GitSCM', branches: [[name: branch]], + userRemoteConfigs: [[url: url]]]) +} + +def checkout(String url){ + checkout(url, "master") +} + +def checkoutOnBuildConfig(String target_dir){ + String scm_url = scm.getUserRemoteConfigs()[0].getUrl() + if(scm_url.contains("on-build-config")){ + dir(target_dir){ + checkout scm + } + }else { + checkout("https://github.com/RackHD/on-build-config", master, target_dir) + } +} + +def getLockedResourceName(String label_name){ + // Get the resource name whose label contains the parameter label_name + // The locked resources of the build + def resources=org.jenkins.plugins.lockableresources.LockableResourcesManager.class.get().getResourcesFromBuild(currentBuild.getRawBuild()) + def resources_name=[] + for(int i=0;i used_resources){ + // The locked resources whose label contains the parameter label_name + resources = getLockedResourceName(label_name) + def available_resources = resources - used_resources + if(available_resources.size > 0){ + used_resources.add(available_resources[0]) + String resource_name = available_resources[0] + return resource_name + } + else{ + error("There is no available resources for $label_name") + } +} + +def parseJsonResource(String resource_path){ + def json_text = libraryResource(resource_path) + def props = readJSON text: json_text + return props +} + +return this diff --git a/workflows/pr_gate/Jenkinsfile b/workflows/pr_gate/Jenkinsfile index d745960..c03b597 100644 --- a/workflows/pr_gate/Jenkinsfile +++ b/workflows/pr_gate/Jenkinsfile @@ -1,8 +1,8 @@ -@Library('my_library') _ +@Library("my_library") _ node{ timestamps{ - def manifest = new pipeline.common.Manifest() def unit_test = new pipeline.rackhd.source_code.UnitTest() + def manifest = new pipeline.common.Manifest() manifest.downloadManifest("https://dl.bintray.com/rackhd/binary/master-20170806","master-20170806") stash name: "prgate_manifest", includes: "master-20170806"