0

I've found tons of information/example in order to move a Jenkins job into a new folder or subfolder, for example:

How to move jenkins job to sub folder?

I also easily found information regarding how to manually (from the GUI) move a job from a Jenkins tab to another one, for example:

How to move an existing job from one view to another in Jenkins?

However, I couldn't find any information regarding how to move a Jenkins job to a new view programatically ? I can't believe this isn't possible ... Does anyone have any hint?

hublo
  • 1,010
  • 2
  • 12
  • 33
  • Ok, this could do the trick: https://stackoverflow.com/questions/12303629/how-to-programmatically-add-a-job-to-a-view-in-hudson – hublo May 07 '18 at 13:33

1 Answers1

0

Our team have a Tv show a specific view of Jenkins, when a job have problem they will come this View. When Job it's ok it's leave the Tv view, like this:

import jenkins.model.*
import hudson.model.*

def jobName = "MyJob"
def j = Jenkins.getInstance();
def viewAll = j.getView("All")
def tvView = j.getView("TeamTv")

if(manager.build.getResult() == Result.FAILURE){
    //If FAILURE move to Tv
    def job = viewAll.getJob(jobName)

    if(job != null){
        tvView.add(job)
        viewAll.remove(job)
    }
    manager.build.displayName = "Dudes, we have problem!";       

}else{
    def job = tvView.getJob(jobName)

    if(job != null){
       viewAll.add(job)
       tvView.remove(job)
    }
}
Wender
  • 991
  • 15
  • 24