Build fails intermittently on Jenkins node machine - jenkins

I created a build system on windows 2019 server where I installed Jenkins version 2.375.1 and which is running Java 17. I am completely new in this and doing it for first time.
Here is the issue: Whenever I run any job, sometime s(4-6 out of 10) it fails by throwing an exception. See below :
java.nio.channels.ClosedChannelException
at jenkins.agents.WebSocketAgents$Session.closed(WebSocketAgents.java:153)
at jenkins.websocket.WebSockets$1.onWebSocketClose(WebSockets.java:80)
at jenkins.websocket.Jetty10Provider$2.onWebSocketClose(Jetty10Provider.java:149)
at org.eclipse.jetty.websocket.common.JettyWebSocketFrameHandler.notifyOnClose(JettyWebSocketFrameHandler.java:308)
at org.eclipse.jetty.websocket.common.JettyWebSocketFrameHandler.onClosed(JettyWebSocketFrameHandler.java:292)
at org.eclipse.jetty.websocket.core.internal.WebSocketCoreSession.lambda$closeConnection$0(WebSocketCoreSession.java:272)
at org.eclipse.jetty.server.handler.ContextHandler.handle(ContextHandler.java:1450)
at org.eclipse.jetty.server.handler.ContextHandler.handle(ContextHandler.java:1487)
at org.eclipse.jetty.websocket.core.server.internal.AbstractHandshaker$1.handle(AbstractHandshaker.java:212)
at org.eclipse.jetty.websocket.core.internal.WebSocketCoreSession.lambda$closeConnection$1(WebSocketCoreSession.java:272)
at org.eclipse.jetty.util.Callback$4.completed(Callback.java:184)
at org.eclipse.jetty.util.Callback$Completing.succeeded(Callback.java:344)
at org.eclipse.jetty.websocket.common.JettyWebSocketFrameHandler.onError(JettyWebSocketFrameHandler.java:268)
at org.eclipse.jetty.websocket.core.internal.WebSocketCoreSession.lambda$closeConnection$2(WebSocketCoreSession.java:284)
at org.eclipse.jetty.server.handler.ContextHandler.handle(ContextHandler.java:1468)
at org.eclipse.jetty.server.handler.ContextHandler.handle(ContextHandler.java:1487)
............
............
............
And the log I got in node machine on console is :
INFO: Connected
Jan 15, 2023 8:05:02 AM hudson.remoting.UserRequest perform
WARNING: LinkageError while performing
UserRequest:hudson.node_monitors.SwapSpaceMonitor$MonitorTask#4c55cc1c
java.lang.UnsatisfiedLinkError: C:\Users\test*****\AppData\Local\Temp\jna--202642030\jna2121667260400486382.dll: A dynamic link library (DLL) initialization routine failed
at java.base/jdk.internal.loader.NativeLibraries.load(Native Method)
at java.base/jdk.internal.loader.NativeLibraries$NativeLibraryImpl.open(NativeLibraries.java:388)
at java.base/jdk.internal.loader.NativeLibraries.loadLibrary(NativeLibraries.java:232)
at java.base/jdk.internal.loader.NativeLibraries.loadLibrary(NativeLibraries.java:174)
at java.base/java.lang.ClassLoader.loadLibrary(ClassLoader.java:2389)
at java.base/java.lang.Runtime.load0(Runtime.java:755)
at java.base/java.lang.System.load(System.java:1953)
at com.sun.jna.Native.loadNativeDispatchLibraryFromClasspath(Native.java:1045)
at com.sun.jna.Native.loadNativeDispatchLibrary(Native.java:1015)
at com.sun.jna.Native.<clinit>(Native.java:221)
at com.sun.jna.Structure.setAlignType(Structure.java:291)
at com.sun.jna.Structure.<init>(Structure.java:208)
at com.sun.jna.Structure.<init>(Structure.java:204)
at com.sun.jna.Structure.<init>(Structure.java:191)
at com.sun.jna.Structure.<init>(Structure.java:183)
at org.jvnet.hudson.Windows$MEMORYSTATUSEX.<init>(Windows.java:67)
Some more info about configuration :
Both controller and node machine is windows server 2019
Since in latest Jenkins the java web connect(Run Jenkins as service on node) is not available so directly running the agent command in node's CLI.
Both controller and node is running Java v17
I went through couple of links and tried all the possible suggestion provided like power management settings on salve machine, increasing Jenkins build timeout settings etc... but no luck.
Any help on this is highly appreciated.
Thanks.

Not sure if there is a bug in Jenkins itself or something. I could not find the answer of the exact issue but after making some changes in jenkins configuration, now i am able to run all the jobs without getting above exception.
Here it is : Earlier i checked jenkins to use websocket in slave configuration. If i just disable it and run then not getting any issue.
Just disbaling this worked for me.. Thanks.

Related

Jenkins System configuration error when saving

An instance of Jenkins started not saving changes made under 'Manage Jenkins > System Configuration'.
In an attempt to solve it, I have recently upgraded to Jenkins 2.346.3 (including all the plugins).
Unfortunately, this behavior still persists and the System Log only shows:
Error while serving http://<jenkins_url>/configSubmit
java.lang.ClassCastException: java.lang.Integer cannot be cast to hudson.model.Describable
at hudson.util.DescribableList.get(DescribableList.java:128)
at hudson.util.DescribableList.rebuild(DescribableList.java:170)
at jenkins.model.GlobalNodePropertiesConfiguration.configure(GlobalNodePropertiesConfiguration.java:24)
at jenkins.model.Jenkins.configureDescriptor(Jenkins.java:4017)
at jenkins.model.Jenkins.doConfigSubmit(Jenkins.java:3981)
at java.lang.invoke.MethodHandle.invokeWithArguments(MethodHandle.java:627)
at org.kohsuke.stapler.Function$MethodFunction.invoke(Function.java:397)
Caused: java.lang.reflect.InvocationTargetException
at org.kohsuke.stapler.Function$MethodFunction.invoke(Function.java:401)
at org.kohsuke.stapler.Function$InstanceFunction.invoke(Function.java:409)
at org.kohsuke.stapler.Function.bindAndInvoke(Function.java:207)
<snippet>
Any idea on the possible cause?
UPDATE
After 2 attempts on restarting Jenkins without the config.xml, I succeeded in having Jenkins 'Manage Jenkins > System Configuration' behaving as expected.
After the first attempt, I reverted to the old configuration file as all the security related configurations were missing and I ended up raising the ticket https://issues.jenkins.io/browse/JENKINS-69548
On the 2nd attempt, I did what I described in the ticket comment https://issues.jenkins.io/browse/JENKINS-69548?focusedCommentId=430091&page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#comment-430091 (i.e. re-introducing the security-related configurations)
You probably have a corrupted config.xml from your old installation. Try deleting the config.xml(Back it up) located at $JENKINS_HOME(if you have not changed the default JENKINS_HOME in most cases it will be at USER_HOME/.jenkins(~/.jenkins)) and restarting Jenkins. If it's successful you can start reconfiguring or moving the configs from there.

How to fix Jenkins java.lang.IllegalStateException: An attempt to save the global configuration was made before it was loaded

I upgraded from jenkins 2.219 to 2.272 (latest version as of this writing) and now getting the stack trace below when Jenkins starts.
Jenkins docs says that this happens due to the Configuration as Code plugin and to set the jvm args as -Dio.jenkins.plugins.casc.ConfigurationAsCode.initialDelay=9000. The docs also say to increment the value until the error goes away but so far I'm at 480000 and still getting the error. I also don't see that I have the Configuration as Code plugin installed anyway.
How can this be fixed?
java.lang.IllegalStateException: An attempt to save the global configuration was made before it was loaded
at jenkins.model.Jenkins.save(Jenkins.java:3379)
at jenkins.model.Jenkins.saveQuietly(Jenkins.java:3398)
at jenkins.model.Jenkins.setSecurityRealm(Jenkins.java:2637)
at jenkins.model.Jenkins$16.run(Jenkins.java:3342)
at org.jvnet.hudson.reactor.TaskGraphBuilder$TaskImpl.run(TaskGraphBuilder.java:169)
at org.jvnet.hudson.reactor.Reactor.runTask(Reactor.java:296)
at jenkins.model.Jenkins$5.runTask(Jenkins.java:1129)
at org.jvnet.hudson.reactor.Reactor$2.run(Reactor.java:214)
at org.jvnet.hudson.reactor.Reactor$Node.run(Reactor.java:117)
at jenkins.security.ImpersonatingExecutorService$1.run(ImpersonatingExecutorService.java:68)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
Caused: org.jvnet.hudson.reactor.ReactorException
at org.jvnet.hudson.reactor.Reactor.execute(Reactor.java:282)
at jenkins.InitReactorRunner.run(InitReactorRunner.java:50)
at jenkins.model.Jenkins.executeReactor(Jenkins.java:1162)
at jenkins.model.Jenkins.<init>(Jenkins.java:962)
at hudson.model.Hudson.<init>(Hudson.java:85)
at hudson.model.Hudson.<init>(Hudson.java:81)
at hudson.WebAppMain$3.run(WebAppMain.java:295)
Caused: hudson.util.HudsonFailedToLoad
at hudson.WebAppMain$3.run(WebAppMain.java:312)
For anyone having this issue, yes downgrading to https://get.jenkins.io/war-stable/2.263.1/ first is required. Then restart the service, then upgrade all of your plugins, then try the LTS upgrade again, at least for me it worked just fine.
More details about the issue here:
https://www.jenkins.io/doc/upgrade-guide/2.204/
SEVERE jenkins.InitReactorRunner$1#onTaskFailed: Failed
ConfigurationAsCode.init java.lang.IllegalStateException: An attempt
to save the global configuration was made before it was loaded If
you encounter this, you can tell the plugin to delay configuration for
an amount of time to give Jenkins time to load the global
configuration before the configuration is applied by the plugin.
To enable this set the
io.jenkins.plugins.casc.ConfigurationAsCode.initialDelay system
property to a number of milliseconds to delay the initialisation. The
required value will be dependant on aspects of your system (cpu/disk)
and configuration, and how it can be found is mostly a trial and
error. A suggestion would be to start with 5000 (5 Seconds) and then
increment by 2000 (2 seconds) until you no longer exhibit the issue
and finally add 1000 (1 second) for some extra safety. For example, to
delay the configuration by 9 seconds you would use something like the
following command java
-Dio.jenkins.plugins.casc.ConfigurationAsCode.initialDelay=9000 -jar jenkins.war. Exactly how and where you specify this option depends on
the installation method used to install Jenkins
However for me the workaround didnt work without first downgrading, upgrading all plugins, then finally upgrading the core again.
To avoid this issue beforehand when you actually have not installed the Casc plugin:
Update to https://github.com/jenkinsci/role-strategy-plugin/releases/tag/role-strategy-3.1 and you should be OK.
When jenkins is already in the faulty state:
download the hpi and drop the hpi file into JENKINS_HOME/plugins folder.
https://updates.jenkins.io/download/plugins/role-strategy/
(information taken from: https://github.com/jenkinsci/configuration-as-code-plugin/issues/1531)
I faced the same issue. I have downloaded the jenkins.war , the earlier version (2.263.1) from https://www.jenkins.io/download/ . Stopped the jenkins and replaced the war with my install directory(C:\Program Files\Jenkins). And started the jenkins.This works like a charm.
You can download the hpi and drop the hpi file into JENKINS_HOME/plugins folder. Usually the jenkins plugin directory will be under - /var/lib/jenkins/plugins/.
The link to get Role strategy hpi plugin - https://updates.jenkins.io/latest/role-strategy.hpi. And restart Jenkins using this command: systemctl restart jenkins.
My scenario was to upgrade the Jenkins to the latest version and then restore the data in it to work like it was working before.
While upgrading from Jenkins v2.263 to v2.303, I had the same error. The only thing which worked for me was to upgrade my global plugin i.e Role-based authorization strategy first, and then Jenkins. It worked like a crisp.
We had the same issue after we upgraded to the latest version.
After some searching we decided to go with a lower version which has LTS support, 2.263.1 in this case.
That version worked instantly so I think this error is a bug.
we has similar issue, resolved by downgrading the jenkins.war file downloaded from URL: https://get.jenkins.io/war-stable/2.263.1/
I have faced similar issue, and found that we don't need to downgrade version.
Below are the steps I performed and it worked for me
upgrade global plugin i.e Role-based authorization strategy first from Jenkins Console.
Here are steps which I have performed:
#on ubuntu, in /usr/share/jenkins:
sudo service jenkins stop
sudo mv jenkins.war jenkins.war.old
sudo wget https://updates.jenkins-ci.org/latest/jenkins.war
sudo chown -R jenkins:jenkins jenkins.war
sudo service jenkins start
I have the same error on Jenkins 2.332.2 and updated plugin role-strategy v483.v17281966f5c3.
I had to download the version 3.2.0 of the plugin and put it directly in the jenkins plugins folder. (previously I remove the existing '.jpi' file)
Then restarting Jenkins /etc/init.d/jenkins restart, and the issue has gone.
Thank you for the intel!

debug openresty with zerobrane

I've followed this tutorial to setting up Zerobrane IDE for debugging openresty:
http://notebook.kulchenko.com/zerobrane/debugging-openresty-nginx-lua-scripts-with-zerobrane-studio.
I installed openresty 1.19.3.1 from a brew formula, and lua scripts are working.
Double checked everything with zerobrane, the error i got:
Debugger server started at vgh.local:8172.
Can't start debugging for '/usr/local/Cellar/openresty/1.19.3.1_1/nginx/lua/content.lua'. Compilation error:
Debugger connection closed
Debugging session completed (traced 0 instructions).
Refused a request to start a new debugging session as there is one in progress already.
What should i check?
This is the conf i have on macos, but i got the same error on a linux (ubuntu 20.10):
lua_package_path '/Applications/ZeroBraneStudio.app/Contents/ZeroBraneStudio/lualibs/?/?.lua;/Applications/ZeroBraneStudio.app/Contents/ZeroBraneStudio/lualibs/?.lua;;';
lua_package_cpath '/Applications/ZeroBraneStudio.app/Contents/ZeroBraneStudio/bin/clibs/?.dylib;;';
You don't say what version of ZeroBrane Studio you are using, but you'll need to use the latest one from the master branch in the repository, as there have been several openresty-related fixes applied to the debugger and merged recently .

I can't change java memory for Jenkins

Note: My OS Debian 7, Java 8, 2Gb RAM
Here is what I did:
I went this way: /etc/default/
Then: vim jenkins
Then edit: JAVA_ARGS="-Xmx1048m"
I exit from editor with saving: :wq
Now I make do: service jenkins restart
Now I go to my Jenkins and watching monitoring with plugin JavaMelody.
So, I see that no changes have occurred.
I ask for help in this case, please.
From the official guide, if you're using RedHat Linux based distributions, you should use JENKINS_JAVA_OPTIONS.
JENKINS_JAVA_OPTIONS="-Xmx1048m"
Note: For me, the file location was /etc/sysconfig/jenkins and it only had JENKINS_ARGS="". Assigning Xmx value to it did not work. You should leave that entry as is and instead, add the JENKINS_JAVA_OPTIONS entry in the file just like i specified above.
The problem is resolved and I did the following:
I went this way: /etc/default/
Then: vim jenkins
I'm add in jenkins JAVA=/usr/bin/java
and JAVA_ARGS="-Djava.awt.headless=true -Xmx1024m"
I exit from editor with saving: :wq
Then after I made: service jenkins restart
Now I go to my Jenkins and watching monitoring with plugin JavaMelody.
So, I see that this works for me.
I'm hope this helps someone.

Issue with C# sonarqube plugin

I have a SonarQube 5.6 installed since a year now, It's integrated with TFS. Installed with few additional plugins, C#, dependency-check, fxcop, java, Checkmarx, scm-cvs, scm-git, scm-svn and scm-tfvc.
everything was working fine. Today it's started failing build with error
2017-06-26T17:54:22.7387533Z Downloading SonarQube.MSBuild.Runner.Implementation.zip from http://xxxxxxx:9000/static/csharp/SonarQube.MSBuild.Runner.Implementation.zip to E:\agnt\_work\41\.sonarqube\bin\SonarQube.MSBuild.Runner.Implementation.zip
2017-06-26T17:54:22.7397520Z ##[error]Could not find a file on the SonarQube server. Url: http://xxxxxxxxxx:9000/static/csharp/SonarQube.MSBuild.Runner.Implementation.zip
2017-06-26T17:54:22.7407523Z ##[error]Failed to update the SonarQube Scanner for MSBuild binaries. Check the server url, verify that the C# plugin is correctly installed on the SonarQube server and that the SonarQube server has been restarted.
2017-06-26T17:54:22.7417526Z ##[error]Pre-processing failed. Exit code: 1
2017-06-26T17:54:22.8678238Z ##[error]System.Exception: Unexpected exit code received from batch file: 1
2017-06-26T17:54:22.8698250Z ##[error] at Microsoft.TeamFoundation.DistributedTask.Task.Internal.PowerShell.InvokeBatchScriptCmdlet.ProcessRecord()
2017-06-26T17:54:22.8708248Z ##[error] at System.Management.Automation.CommandProcessor.ProcessRecord()
From the error, I can it's something related to C# plugin. I checked that plugin under /extensions/plugins and it's there. I thought it can be something compatibility issue, I tried to upgrade it to latest one 6.0
After installing 6.0 tried again and got the same error.
I also tried with old version of same plugins. tried 5.3, 5.0. After manually copied jar file under /plugins. Tried to restart the sonar server and it didn't started successfully. I got the error as below,
2017.06.26 18:31:11 ERROR web[o.s.s.p.Platform] Fail to stop server - ignored
java.lang.IllegalStateException: Cannot stop. Current container state was: CONSTRUCTED at org.picocontainer.lifecycle.DefaultLifecycleState.stopping(DefaultLifecycleState.java:72) ~[picocontainer-2.15.jar:na] at org.picocontainer.DefaultPicoContainer.stop(DefaultPicoContainer.java:794) ~[picocontainer-2.15.jar:na]
2017.06.26 18:31:11 ERROR web[o.a.c.c.C.[.[.[/]] Exception sending context initialized event to listener instance of class org.sonar.server.platform.PlatformServletContextListener
java.lang.IllegalStateException: Fail to load plugin FxCop [fxcop] at org.sonar.server.plugins.ServerExtensionInstaller.installExtensions(ServerExtensionInstaller.java:74) ~[sonar-server-5.6.jar:na] at org.sonar.server.platform.platformlevel.PlatformLevel4.start(PlatformLevel4.java:691) ~[sonar-server-5.6.jar:na] at org.sonar.server.platform.Platform.start(Platform.java:216) ~[sonar-server-5.6.jar:na]
Caused by: java.lang.IllegalStateException: Unable to register extension org.sonar.api.config.PropertyDefinition at org.sonar.core.platform.ComponentContainer.addExtension(ComponentContainer.java:248) ~[sonar-core-5.6.jar:na] at org.sonar.server.plugins.ServerExtensionInstaller.installExtension(ServerExtensionInstaller.java:111) ~[sonar-server-5.6.jar:na] at org.sonar.server.plugins.ServerExtensionInstaller.installExtensions(ServerExtensionInstaller.java:66) ~[sonar-server-5.6.jar:na]
Caused by: org.picocontainer.PicoCompositionException: Duplicate Keys not allowed. Duplicate for 'org.sonar.api.config.PropertyDefinition-sonar.cs.fxcop.timeoutMinutes'at org.picocontainer.DefaultPicoContainer.addAdapterInternal(DefaultPicoContainer.java:438) ~[picocontainer-2.15.jar:na]
2017.06.26 18:31:11 ERROR web[o.a.c.c.StandardContext] One or more listeners failed to start. Full details will be found in the appropriate container log file 2017.06.26 18:31:11 ERROR web[o.a.c.c.StandardContext] Context [] startup failed due to previous errors
2017.06.26 18:31:11 WARN web[o.a.c.l.WebappClassLoaderBase] The web application [ROOT] appears to have started a thread named [Timer-0] but has failed to stop it. This is very likely to create a memory leak. Stack trace of thread
2017.06.26 18:31:11 WARN web[o.s.p.ProcessEntryPoint] Fail to start web
java.lang.IllegalStateException: Webapp did not start at org.sonar.server.app.EmbeddedTomcat.isUp(EmbeddedTomcat.java:84) ~[sonar-server-5.6.jar:na]at org.sonar.server.app.WebServer.isUp(WebServer.java:47) [sonar-server-5.6.jar:na]at org.sonar.process.ProcessEntryPoint.launch(ProcessEntryPoint.java:105) ~[sonar-process-5.6.jar:na]at org.sonar.server.app.WebServer.main(WebServer.java:68) [sonar-server5.6.jar:na]
can someone please help to fix this issue?
You need to update the Scanner for MsBuild as well. The old versions are not compatible with SonarC# 6+.
I fixed this issue by removing FxCop plugin. Somehow that plugin stopped working. can be the version what i was using that was not compatible with C# plugin. I installed C# plugin version 5.0 (latest is 6.0)
as mentioned above, if i want to use C# latest version, i need to update sonar scanner for MSBuild.

Resources