-
Bug
-
Resolution: Unresolved
-
Minor
-
None
-
Powered by SuggestiMate
Jobs created with JCASC using Job DSL are not queued on startup.
Jcasc config added for creating a freestyle Job and queue it for run the JOb on startup. Jenkins has the Job created but the Job dint run on startup even after queuing.
// code placeholder jobs: - script: > freeStyleJob('Seed_job') { scm { git{ branch('master') remote{ credentials('github_e_token') url('https://github.com/jenkins_bootstrap.git') } } } triggers { githubPush() } steps { dsl { external('seedJob.groovy') removeAction('DELETE') } } } - script: queue('Seed_job')
[JENKINS-62606] Jobs created with JCASC using Job dsl are not queued on start up.
I second this report. Here's the startup log where we can see that it schedules a build according to the logs but somehow the job is never run.
2020-06-09 06:01:05.134+0000 [id=1] INFO hudson.WebAppMain#contextInitialized: Jenkins home directory: /var/jenkins_home found at: EnvVars.masterEnvVars.get("JENKINS_HOME") 2020-06-09 06:01:05.507+0000 [id=1] INFO o.e.j.s.handler.ContextHandler#doStart: Started w.@df5f5c0{Jenkins v2.222.3,/jenkins,file:///var/jenkins_home/war/,AVAILABLE}{/var/jenkins_home/war} 2020-06-09 06:01:05.567+0000 [id=1] INFO o.e.j.server.AbstractConnector#doStart: Started ServerConnector@6025e1b6{HTTP/1.1, (http/1.1)}{0.0.0.0:8080} 2020-06-09 06:01:05.568+0000 [id=1] INFO org.eclipse.jetty.server.Server#doStart: Started @2904ms 2020-06-09 06:01:05.568+0000 [id=23] INFO winstone.Logger#logInternal: Winstone Servlet Engine running: controlPort=disabled 2020-06-09 06:01:06.137+0000 [id=29] INFO jenkins.InitReactorRunner$1#onAttained: Started initialization 2020-06-09 06:01:09.132+0000 [id=29] INFO jenkins.InitReactorRunner$1#onAttained: Listed all plugins 2020-06-09 06:01:17.931+0000 [id=34] INFO jenkins.InitReactorRunner$1#onAttained: Prepared all plugins 2020-06-09 06:01:22.100+0000 [id=32] INFO jenkins.InitReactorRunner$1#onAttained: Started all plugins 2020-06-09 06:01:22.125+0000 [id=31] INFO jenkins.InitReactorRunner$1#onAttained: Augmented all extensions 2020-06-09 06:01:23.656+0000 [id=35] INFO jenkins.InitReactorRunner$1#onAttained: System config loaded 2020-06-09 06:01:25.581+0000 [id=31] WARNING i.j.p.casc.BaseConfigurator#createAttribute: Can't handle class javaposse.jobdsl.plugin.GlobalJobDslSecurityConfiguration#metaClass: type is abstract but not Describable. 2020-06-09 06:01:27.131+0000 [id=31] INFO o.s.c.s.AbstractApplicationContext#prepareRefresh: Refreshing org.springframework.web.context.support.StaticWebApplicationContext@5cc69bc4: display name [Root WebApplicationContext]; startup date [Tue Jun 09 08:01:27 CEST 2020]; root of context hierarchy 2020-06-09 06:01:27.131+0000 [id=31] INFO o.s.c.s.AbstractApplicationContext#obtainFreshBeanFactory: Bean factory for application context [org.springframework.web.context.support.StaticWebApplicationContext@5cc69bc4]: org.springframework.beans.factory.support.DefaultListableBeanFactory@56f193fe 2020-06-09 06:01:27.142+0000 [id=31] INFO o.s.b.f.s.DefaultListableBeanFactory#preInstantiateSingletons: Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@56f193fe: defining beans [authenticationManager,activeDirectory]; root of factory hierarchy 2020-06-09 06:01:27.280+0000 [id=31] INFO o.s.c.s.AbstractApplicationContext#prepareRefresh: Refreshing org.springframework.web.context.support.StaticWebApplicationContext@1d219850: display name [Root WebApplicationContext]; startup date [Tue Jun 09 08:01:27 CEST 2020]; root of context hierarchy 2020-06-09 06:01:27.280+0000 [id=31] INFO o.s.c.s.AbstractApplicationContext#obtainFreshBeanFactory: Bean factory for application context [org.springframework.web.context.support.StaticWebApplicationContext@1d219850]: org.springframework.beans.factory.support.DefaultListableBeanFactory@42f70773 2020-06-09 06:01:27.280+0000 [id=31] INFO o.s.b.f.s.DefaultListableBeanFactory#preInstantiateSingletons: Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@42f70773: defining beans [filter,legacy]; root of factory hierarchy 2020-06-09 06:01:28.020+0000 [id=31] WARNING i.j.p.casc.BaseConfigurator#createAttribute: Can't handle class javaposse.jobdsl.plugin.GlobalJobDslSecurityConfiguration#metaClass: type is abstract but not Describable. Processing provided DSL script 2020-06-09 06:01:29.759+0000 [id=78] WARNING j.t.i.j.MissingClassTelemetry#reportException: Added a missed class for missing class telemetry. Class: com.sun.jndi.url.java.javaURLContextFactory java.lang.ClassNotFoundException: com.sun.jndi.url.java.javaURLContextFactory at jenkins.util.AntClassLoader.findClassInComponents(AntClassLoader.java:1387) at jenkins.util.AntClassLoader.findClass(AntClassLoader.java:1342) at jenkins.util.AntClassLoader.loadClass(AntClassLoader.java:1089) at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521) at hudson.remoting.RemoteClassLoader$ClassLoaderProxy.fetch4(RemoteClassLoader.java:849) at hudson.remoting.RemoteClassLoader$ClassLoaderProxy.fetch3(RemoteClassLoader.java:893) at jdk.internal.reflect.GeneratedMethodAccessor45.invoke(Unknown Source) at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.base/java.lang.reflect.Method.invoke(Method.java:566) at hudson.remoting.RemoteInvocationHandler$RPCRequest.perform(RemoteInvocationHandler.java:931) at hudson.remoting.Request$2.run(Request.java:369) at hudson.remoting.InterceptingExecutorService$1.call(InterceptingExecutorService.java:72) at org.jenkinsci.remoting.CallableDecorator.call(CallableDecorator.java:18) at hudson.remoting.CallableDecoratorList$1.call(CallableDecoratorList.java:21) at jenkins.util.ContextResettingExecutorService$2.call(ContextResettingExecutorService.java:46) at jenkins.security.ImpersonatingExecutorService$2.call(ImpersonatingExecutorService.java:71) at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264) at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128) at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628) at java.base/java.lang.Thread.run(Thread.java:834) 2020-06-09 06:01:32.260+0000 [id=31] INFO j.j.plugin.JenkinsJobManagement#createOrUpdateConfig: createOrUpdateConfig for Seed-Job Processing provided DSL script 2020-06-09 06:01:32.578+0000 [id=31] INFO j.j.plugin.JenkinsJobManagement#queueJob: Scheduling build of Seed-Job from Seed-Job 2020-06-09 06:01:32.593+0000 [id=31] INFO jenkins.InitReactorRunner$1#onAttained: System config adapted 2020-06-09 06:01:32.594+0000 [id=31] INFO jenkins.InitReactorRunner$1#onAttained: Loaded all jobs 2020-06-09 06:01:32.602+0000 [id=33] INFO jenkins.InitReactorRunner$1#onAttained: Configuration for all jobs updated 2020-06-09 06:01:32.608+0000 [id=30] INFO j.util.groovy.GroovyHookScript#execute: Executing /var/jenkins_home/init.groovy.d/tcp-slave-agent-port.groovy 2020-06-09 06:01:32.622+0000 [id=101] INFO hudson.model.AsyncPeriodicWork#lambda$doRun$0: Started Download metadata 2020-06-09 06:01:32.625+0000 [id=101] INFO hudson.model.AsyncPeriodicWork#lambda$doRun$0: Finished Download metadata. 2 ms 2020-06-09 06:01:32.782+0000 [id=34] INFO o.s.c.s.AbstractApplicationContext#prepareRefresh: Refreshing org.springframework.web.context.support.StaticWebApplicationContext@594400ec: display name [Root WebApplicationContext]; startup date [Tue Jun 09 08:01:32 CEST 2020]; root of context hierarchy 2020-06-09 06:01:32.783+0000 [id=34] INFO o.s.c.s.AbstractApplicationContext#obtainFreshBeanFactory: Bean factory for application context [org.springframework.web.context.support.StaticWebApplicationContext@594400ec]: org.springframework.beans.factory.support.DefaultListableBeanFactory@38c5f983 2020-06-09 06:01:32.783+0000 [id=34] INFO o.s.b.f.s.DefaultListableBeanFactory#preInstantiateSingletons: Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@38c5f983: defining beans [filter,legacy]; root of factory hierarchy 2020-06-09 06:01:32.917+0000 [id=33] INFO jenkins.InitReactorRunner$1#onAttained: Completed initialization 2020-06-09 06:01:33.013+0000 [id=22] INFO hudson.WebAppMain$3#run: Jenkins is fully up and running
Jenkins v2.222.3, job-dsl v1.77, configuration-as-code v1.41
I suspect that JobDSL loads the script without waiting for the completion of the previous script.
I am having the same problem on my end. Running latest versions of Jenkins LTS and all plugins.
I also tried the following and although the job was successfully created, it was not queued.
def myJob = job('my-job') {
...
};
queue(myJob);
We've also experienced this problem trying to use the queue method on Jenkins 2.289, job-dsl 1.77 and JCasC 1.47.
I added some extra logging to see what was going on and it looks like there's an order of operations/dependency problem. JCasC/JobDSL are able to queue the job, but that operation happens before the Jenkins Queue is loaded from disk on startup. When the Jenkins Queue is loaded from disk, it clears out the current contents of the queue so the job never gets run. Here's a log snippet from Jenkins running in Docker locally showing the timeline. You can see my-test-job being added to the Queue's waitingList and then disappearing after the queue is loaded from disk.
2021-05-04 16:42:07.589+0000 [id=43] INFO jenkins.InitReactorRunner$1#onAttained: System config loaded [snip...] 2021-05-04 16:42:09.469+0000 [id=32] WARNING i.j.p.casc.BaseConfigurator#createAttribute: Can't handle class javaposse.jobdsl.plugin.GlobalJobDslSecurityConfiguration#metaClass: type is abstract but not Describable. Processing provided DSL script 2021-05-04 16:42:10.796+0000 [id=32] INFO j.j.plugin.JenkinsJobManagement#createOrUpdateConfig: createOrUpdateConfig for my-test-job Processing provided DSL script 2021-05-04 16:42:11.342+0000 [id=32] INFO j.j.plugin.JenkinsJobManagement#queueJob: Scheduling build of my-test-job from my-test-job 2021-05-04 16:42:11.406+0000 [id=32] INFO hudson.model.Queue#updateSnapshot: Queue.Snapshot{waitingList=[];blockedProjects=[];buildables=[];pendings=[]} → Queue.Snapshot{waitingList=[hudson.model.Queue$WaitingItem:hudson.model.FreeStyleProject@4de8b083[my-test-job]:1];blockedProjects=[];buildables=[];pendings=[]}; leftItems={} 2021-05-04 16:42:11.406+0000 [id=32] INFO hudson.model.Queue#updateSnapshot: Queue.Snapshot{waitingList=[hudson.model.Queue$WaitingItem:hudson.model.FreeStyleProject@4de8b083[my-test-job]:1];blockedProjects=[];buildables=[];pendings=[]} → Queue.Snapshot{waitingList=[hudson.model.Queue$WaitingItem:hudson.model.FreeStyleProject@4de8b083[my-test-job]:1];blockedProjects=[];buildables=[];pendings=[]}; leftItems={} 2021-05-04 16:42:11.406+0000 [id=74] INFO hudson.model.Queue#maintain: Queue maintenance started on hudson.model.Queue@440691fe with Queue.Snapshot{waitingList=[hudson.model.Queue$WaitingItem:hudson.model.FreeStyleProject@4de8b083[my-test-job]:1];blockedProjects=[];buildables=[];pendings=[]} 2021-05-04 16:42:11.407+0000 [id=32] INFO jenkins.InitReactorRunner$1#onAttained: System config adapted 2021-05-04 16:42:11.408+0000 [id=31] INFO jenkins.InitReactorRunner$1#onAttained: Loaded all jobs 2021-05-04 16:42:11.409+0000 [id=40] INFO jenkins.InitReactorRunner$1#onAttained: Configuration for all jobs updated 2021-05-04 16:42:11.411+0000 [id=74] INFO hudson.model.Queue#updateSnapshot: Queue.Snapshot{waitingList=[hudson.model.Queue$WaitingItem:hudson.model.FreeStyleProject@4de8b083[my-test-job]:1];blockedProjects=[];buildables=[];pendings=[]} → Queue.Snapshot{waitingList=[hudson.model.Queue$WaitingItem:hudson.model.FreeStyleProject@4de8b083[my-test-job]:1];blockedProjects=[];buildables=[];pendings=[]}; leftItems={} 2021-05-04 16:42:11.411+0000 [id=74] INFO hudson.model.Queue#updateSnapshot: Queue.Snapshot{waitingList=[hudson.model.Queue$WaitingItem:hudson.model.FreeStyleProject@4de8b083[my-test-job]:1];blockedProjects=[];buildables=[];pendings=[]} → Queue.Snapshot{waitingList=[hudson.model.Queue$WaitingItem:hudson.model.FreeStyleProject@4de8b083[my-test-job]:1];blockedProjects=[];buildables=[];pendings=[]}; leftItems={} 2021-05-04 16:42:11.413+0000 [id=41] WARNING hudson.model.Queue#load: LOADING QUEUE 2021-05-04 16:42:11.414+0000 [id=41] INFO hudson.model.Queue#updateSnapshot: Queue.Snapshot{waitingList=[hudson.model.Queue$WaitingItem:hudson.model.FreeStyleProject@4de8b083[my-test-job]:1];blockedProjects=[];buildables=[];pendings=[]} → Queue.Snapshot{waitingList=[];blockedProjects=[];buildables=[];pendings=[]}; leftItems={} [snip...]
Loading the queue happens after the JOB_CONFIG_ADAPTED milestone ('Configuration for all jobs updated' in the log snippet above):
/** * Restores the queue content during the start up. */ @Initializer(after=JOB_CONFIG_ADAPTED) public static void init(Jenkins h) { h.getQueue().load(); }
JCasC is configured to run after the SYSTEM_CONFIG_LOADED milestone and before the SYSTEM_CONFIG_ADAPTED milestone:
@Restricted(NoExternalUse.class) @Initializer(after = InitMilestone.SYSTEM_CONFIG_LOADED, before = InitMilestone.SYSTEM_CONFIG_ADAPTED) public static void init() throws Exception { detectVaultPluginMissing(); get().configure(); }
So it seems like for this to work it'd need to be possible to add the job to
the queue after the COMPLETED milestone. Not sure that's possible to do within the
confines of JCasC and JobDSL?
I've stumbled on this issue, and as a workaround, I added an init script in 'init.groovy.d' to queue the jobs I want at Jenkins starts.
// File: $JENKINS_HOME/init.groovy.d/queue-jobs.groovy import javaposse.jobdsl.dsl.DslScriptLoader import javaposse.jobdsl.plugin.JenkinsJobManagement println 'Queuing seed-job at Jenkins startup ...' def jobManagement = new JenkinsJobManagement(System.out, [:], new File('.')) new DslScriptLoader(jobManagement).runScript('queue("seed-job")')
There is an issue opened in JCASC plugin which is closed to create an issue under Job DSL plugin.
https://github.com/jenkinsci/configuration-as-code-plugin/issues/876