New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Generate explicit seed job and run it once during start-up #876
Comments
You can use jobs:
- script: |
job('PROJ-unit-tests') {
scm {
git(gitUrl)
}
triggers {
scm('*/15 * * * *')
}
steps {
maven('-e clean test')
}
} |
I guess this means to run the job every 15 minutes? This would mean a lot of unnecessary runs IMHO... Jenkins also displays a warning for this cron expression btw.
|
we use the following However it only seems to work 50% of the time...
After some additional research this could be related to #619 I wonder if I'm just using an older version of the JCasC plugin. |
Confirming that I also still this behavior. Running Casc plugin 1.27 and Jobs-DSL plugin 1.175 and Jenkins 2.190. For us, it consistently doesn't work. Not sure if this is something different from what @Casz fixed in #619.
|
I am also seeing this behavior. If I reapply the existing config the job will queue, but it doesn't queue on start up. This is with CasC plugin 1.31 and Job-DSL 1.76 - script: >
pipelineJob('unit-tests') {
.............
}
- script: queue('unit-tests') |
Well I may have found a workaround that works for me. Using startup-trigger-plugin:2.9.3 and adding a trigger to my pipeline I was able to get the job to start on start up. There are still issues with trying to queue the job with - script: queue('unit-tests'). - script: >
pipelineJob('unit-tests') {
triggers {
hudsonStartupTrigger {
quietPeriod("60")
runOnChoice("ON_CONNECT")
label("")
nodeParameterName("")
}
}
.............
}
|
@rmmacala Nice workaround, works for me! Still would be nice to see the |
Now that jenkinsci/jenkins#4450 has been merged, does this PR help us with the wonky |
Sadly no as JCasC is the trigger for loading JobDSL. I do believe we need to add something to better control when the JobDSL get's triggered to get it to trigger absolutely last. |
I believe #1394 will indeed fix the order of execution for Job DSL being loaded last in JCasC. However running once is something for Job DSL to tackle as they own the configurator for JCasC. Though this can be achieved with a self removing seed job. |
@jetersen not sure I completely understand what the current status is. I just tried - script: >
pipelineJob('unit-tests') {
.............
}
- script: queue('unit-tests') which creates the job correctly but does not run it once during start-up. So basically the |
This would be an issue for the Job DSL plugin to solve. |
I'm currently solving this with a seed-job that overwrites itself. Which feels like a simple solution. You add a seed-job to your jcasc configuration which has an You get multiple maintenance, since you have the job in two places. This is a minor issue for me since the job should literally do two things, reference a repository and trigger, and afterwards just reference the repository if I want to reload the configurations... and I'll probably never want to change this job anyways, unless I change the location of my jobdsl. (Shameless plug) I explain in greater detail here, https://youtu.be/KB7thPsG9VA?t=1919 at 32.00. .. But I'm looking forward to the |
To workaround without maintaining script in multiple places. jcasc: jobs:
- providedEnv:
RUN_AFTER_BOOT: "true"
- script: >
{{ cat file w/e }} seed.groovy job("seed") {
if (binding.hasVariable('RUN_AFTER_BOOT')) { // Only true when creating a new jenkins instance or reloading config
triggers {
cron("H/2 * * * *")
}
}
......
} |
Workaround: you can trigger the seedJob by url. This call can be made by a script for example when inducing jcasc.yaml. |
Feature Request
I have multiple groovy job DSL scripts stored in a Git repository like this:
I would like to define only one pipeline seed job which checks out the Git repository and runs all groovy scripts it can find under the
job-dsl
sub-directory once during JCASC start-up phase (or when triggered manually through the UI or automatically (SCM Poll) later on).Creating this seed job seems possible with the
jobs
directive but AFAICS there is no possibility to have it run once during the JCASC start-up phase, correct?Would it make sense to add this feature or is there something fundamentally wrong in my approach?
The text was updated successfully, but these errors were encountered: