Skip to content

Commit

Permalink
test
Browse files Browse the repository at this point in the history
  • Loading branch information
PengTian0 committed Aug 8, 2017
1 parent 95f5a24 commit 098f868
Show file tree
Hide file tree
Showing 3 changed files with 115 additions and 2 deletions.
46 changes: 46 additions & 0 deletions src/pipeline/common/Manifest.groovy
Original file line number Diff line number Diff line change
@@ -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
}
67 changes: 67 additions & 0 deletions src/pipeline/common/ShareMethod.groovy
Original file line number Diff line number Diff line change
@@ -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<resources.size();i++){
String labels = resources[i].getLabels();
List label_names = Arrays.asList(labels.split("\\s+"));
for(int j=0;j<label_names.size();j++){
if(label_names[j]==label_name){
resources_name.add(resources[i].getName());
}
}
}
return resources_name
}

def occupyAvailableLockedResource(String label_name, ArrayList<String> 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
4 changes: 2 additions & 2 deletions workflows/pr_gate/Jenkinsfile
Original file line number Diff line number Diff line change
@@ -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"
Expand Down

0 comments on commit 098f868

Please sign in to comment.