Running Groovy command from Jenkins using Groovy script plugin

后端 未结 3 515
隐瞒了意图╮
隐瞒了意图╮ 2020-12-10 03:43

I want to force following scenario in Jenkins:

  1. I have job A and job B
  2. I want to disable job A when job B is executed, and after execution of job B, I
相关标签:
3条回答
  • 2020-12-10 04:00

    I think if you run the System Groovy Script, Jenkins objects are available by default. What you are running is the groovy script. Hence, need to import the packages/classes.

    0 讨论(0)
  • 2020-12-10 04:06

    For future readers, Tim's comment above is the solution:

    import jenkins.model.Jenkins

    0 讨论(0)
  • 2020-12-10 04:13

    I ran into the same problem "unable to resolve class jenkins.model.Jenkins" as commented by @iloveretards, until I realized I had tried to use the build step "Execute Groovy script". After switching to build step "Execute system Groovy script", this actually worked as intended:

    import jenkins.model.Jenkins
    Jenkins.instance.getItem("job-name").disable()
    
    0 讨论(0)
提交回复
热议问题