0

I want to implement a healthcheck(invoking an endpoint) in Jenkins, which should run in docker container. I don't want to manually configure my pipeline job in Jenkins every time container is up.

I've tried JCasC, but it doesn't allow to autoconfigure jobs.

How do I automatically configure jobs on first Jenkins launch and trigger them on each time Jenkins is up?

d4nyll
  • 11,811
  • 6
  • 54
  • 68
  • 1
    probably with this plugin: https://plugins.jenkins.io/startup-trigger-plugin – lvthillo Aug 22 '19 at 13:12
  • The [Startup Trigger](https://plugins.jenkins.io/startup-trigger-plugin) plugin mentioned by @lvthillo alongside the [Job DSL](https://plugins.jenkins.io/job-dsl) plugin should do the trick. – d4nyll Sep 26 '19 at 22:30

2 Answers2

2

Here's is an example jobs section of jenkins.yml (CasC config file); it requires the "Job DSL" and "Startup Trigger" plugins (in addition to the "Configuration as Code" plugin, of course):

jobs:
  - script: >
      pipelineJob("Deploy Local2 Stack") {
        description()
        keepDependencies(false)
        triggers {
          hudsonStartupTrigger {
            nodeParameterName("master")
            label("master")
            quietPeriod("0")
            runOnChoice("False")
          }
        }
        definition {
          cpsScm {
            scm {
              git {
                remote {
                  url("https://myrepo/mystuff.git")
                  credentials("scm")
                }
                branch("master")
              }
            }
            scriptPath("pipeline/main/Jenkinsfile")
          }
        }
        disabled(false)
      }

The triggers section is what's important; the rest is just to put it in context.

Apparently, the startup trigger can also work on slave nodes but I gather that's not what you want, so I specified master.

Note: This is the kernel from which I pieced together the solution: https://issues.jenkins-ci.org/browse/JENKINS-41671?focusedCommentId=287026&page=com.atlassian.jira.plugin.system.issuetabpanels%3Acomment-tabpanel#comment-287026

Jamie Jackson
  • 1,158
  • 3
  • 19
  • 34
0

Could you please tell me where you can see all the plugins that can be installed using jcasc? Or where to get the plugins you talked about

Skiv
  • 11
  • 2