如何在Jenkins中使用Job DSL插件删除脚本? [英] How can I delete a job using Job DSL plugin(script) in Jenkins?

查看:124
本文介绍了如何在Jenkins中使用Job DSL插件删除脚本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对Jenkins和Job DSL插件非常陌生.经过一些研究,我发现了如何使用DSL创建作业,现在我正尝试使用DSL删除作业. 我知道使用以下代码禁用作业:

I am very new to Jenkins and Job DSL plugin. After a little research, I found how to create a job using DSL and now I am trying to delete a job using DSL. I know to disable a job using this following code:

//create new job
//freeStyleJob("MyJob1", closure = null);

job("MyJob1"){
  disabled(true);
}

工作正常.但是,我找不到在詹金斯删除其他工作的任何方法.

It is working perfectly fine. But, I couldn't find any method to delete another job in jenkins.

请帮助!

谢谢!

推荐答案

Job Dsl插件的每个实例都跟踪它创建的作业(和视图).再次运行该实例时,您可以配置它对该实例上一次运行时已存在但这次不存在的作业(和视图)的作用.

Each instance of the Job Dsl plugin tracks what jobs (and views) it creates. When it is run again, you can configure what it does to jobs (and views) that were present the previous time this instance was run, but are not present this time.

假设您必须拥有用于创建作业的文件.

Let's a assume you have to files you use to create jobs.

seed_jobdsl.groovy:

job('seed_all') {
  steps {
    dsl {
      external('*_jobdsl.groovy')  
      // default behavior
      // removeAction('IGNORE')      
    }
  }
}

test_jobdsl.groovy:

job('test_stuff') {
  steps {
    shell('echo "I live!")
  }
}

这将使seed_all创建的作业保持不变,即使它们不存在于下次运行种子的创建作业列表中也是如此.

This will leave jobs created by seed_all unchanged even if they are not present in the list of job created the next time seed is run.

要删除作业,请更改您的种子作业代码:

To get jobs to be deleted, change your seed job code:

seed_jobdsl.groovy:

job('seed_all') {
  steps {
    dsl {
      external('*_jobdsl.groovy')  
      removeAction('DELETE')      
    }
  }
}

现在,运行seed_all作业以应用您的更改(seed_all在运行时会覆盖其自身的配置).然后进行以下更改:

Now, run seed_all job to apply your change (seed_all overwrites its own configuration when run). Then make the following change:

test_jobdsl.groovy:

job('test_other') {
  steps {
    shell('echo "The job is dead, long live the new job!"')
  }
}

再次运行seed_all.您会注意到test_stuff将被删除,而test_other将被创建.如果删除test_jobdsl.groovy然后运行seed_all,则会删除test_other.

Run seed_all again. You notice test_stuff will be deleted and test_other will be created. If you remove test_jobdsl.groovy and then run seed_all, test_other will be deleted.

这篇关于如何在Jenkins中使用Job DSL插件删除脚本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆