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 a20dc5f
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 2 deletions.
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 a20dc5f

Please sign in to comment.