Get structure of variables in Jenkins - jenkins

Running println(Jenkins.instance.pluginManager.plugins) in the jenkins console returns lots of useful stuff like:
[Plugin:external-monitor-job, Plugin:docker-workflow,
Plugin:pipeline-rest-api, Plugin:javadoc,
Plugin:resource-disposer, Plugin:conditional-buildstep, ...
]
I want to see the class structure. Where can I find the reference for those classes? Can I generate it? Is it possible to represent those classes like the the variables view in Eclipse, where I can expand all the subclasses and functions?
Those information's are really use full for creating pipeline scripts.

https://javadoc.jenkins-ci.org/hudson/model/Job.html
... and so on.
Maybe some could mention, in a comment how to ask for this information the right way. Is it a api-reference, a class description, a ... ?

Related

Use plugin config as paramater in services.yml

The documentation only shows that you can pass the SystemConfigService as a parameter to another service.
Is there also the possibility to pass directly the value from the plugin configuration?
Background of the question: I would like to initialize directly an instance of an external component. But this expects fixed arguments as strings. Alternatively, one would otherwise have to write some kind of factory.
Hm, it's possible to do. I have not done this directly myself, but 99% confident that it will work. You may need to play around with it a little.
In the services.xml you can use symfony expressions.
<argument type="expression">service('Shopware\Core\System\SystemConfig\SystemConfigService').get('SwagBasicExample.config.example')</argument>
You may need to find the alias name for the Shopware\Core\System\SystemConfig\SystemConfigService class instead. Also check the Symfony documentation, you can do a lot more with this!
I myself passed an array as an argument, but used a custom class as a config getter like so:
<argument type="expression">
{
"shop_is_active": service('config_bridge').get('isActive'),
"customer_number": service('config_bridge').get('customerNumber'),
"shop_number": service('config_bridge').get('shopNumber'),
"apikey": service('config_bridge').get('apiKey')
}
</argument>
Not strictly necessary as Shopware already requires it, but always a good practice to add the requirement to your plugin composer file:
"require": {
...,
"symfony/expression-language": "~5.3.0|~5.4.0"
},
As of today it's not possible to inject specific system_config values in services.

Global shared variables in Jenkins Groovy pipelines

It seems like it's really difficult to be able to store a bunch of variables for use in shared code in Jenkins/Groovy scripted pipelines. I've tried a bunch of methods and none of them seem to give the desired result.
This method looked the most promising, but the values all came back as null in the calling pipeline. Get Global Variables in jenkins pipeline.
My codes is something lie
import org.blabla.JobHelper
println("env.NO_PROXY: -->${env.NO_PROXY}<--")
And in the JobHelper.groovy file, I've defined
package org.blabla.project
env.NO_PROXY = 'localhost,127.0.0.1,169.254.169.254'
the names have been changed a bit to protect the innocent, but you get the idea.
the script just prints null for the value.
Is there a simple way (or indeed any way) that I can pull in a bunch of variables from a shared library file? This feels like it should be a really simple exercise, but after spending many hours searching I'm none the wiser.
In general, env is only available once the pipeline has started, but groovy scripts are resolved much earlier.
I'm using static class members as global variables. Applied to your code sample, it would look like this:
JobHelper.groovy
package org.blabla.project
# Class must be named like the file that contains it.
class JobHelper {
static String getNO_PROXY() { 'localhost,127.0.0.1,169.254.169.254' }
}
Elsewhere:
import org.blabla.project
println("NO_PROXY: -->${JobHelper.NO_PROXY}<--")
Note that Groovy automatically generates properties from get*() and set*() methods, so we can use the short form instead of having to write JobHelper.getNO_PROXY().

Jenkins Job DSL plugin: How do I create a nested view? Example doesn't work for me

I'm in the midst of generating all our views using the Job DSL plugin.
The list views were created without a problem, but now I'm having troubles replacing my nested views.
If I copy & paste the example from https://jenkinsci.github.io/job-dsl-plugin/#path/nestedView , I get the following error:
ERROR: (ViewsGenerator.groovy, line 23) No signature of method: groovy.util.slurpersupport.NodeChild.call() is applicable for argument types: (foobar.jenkins.views.generator.ViewsGenerator$_run_closure1$_closure5) values: [foobar.jenkins.views.generator.ViewsGenerator$_run_closure1$_closure5#4e414e59]
Possible solutions: tail(), wait(), name(), max(), last(), any()
Line 23 is
views {
If I just use
nestedView('ZZZ_project-a') {
}
then Jenkins generates the nested view with that name, but of course it's empty!
I must be doing something very basic in a wrong way :-) but I can't figure it out! Any ideas?
I now tried using the given example directly in a Job DSL generator job (Use the provided DSL script), and that works!
What is the difference between my Groovy script and the one in the textbox?
Ok, after a lot of banging my head on the table :-) I finally found the solution.
As usual, the problem is with my software :-)
I have a helper class called Views which reads some XML etc. etc.
And there's a method called getViews() in there.
For convenience, I usually import such helper classes with
import static Views.*
So, within the Job DSL's nestedView there are views, and apparently Groovy got confused about what views to use, the ones from the Job DSL or my getViews().
I renamed that method to getAllViews(), and the problem was solved.
But getting there (I'm by no means a Groovy expert) was a pretty hard experience, since the error message was very cryptic to me.

IntelliJ Idea auto-complete for my own grails domain meta class methods?

I'm using IntelliJ Idea 10 IDE for my grails development and while it's great at working out the "standard" meta class methods on, for example, domain classes (save, findBy etc), it (obviously) can't pick up methods added by plugins or my own code.
While I don't expect the IDE to be able to pick these up automatically, I'm optimistically wondering if there's a way to tell IntelliJ that, for example, "myMethod" is added to all domain objects, and that it takes a map and returns "myType".
It's a long shot I know, but does anyone know how this might be done in config, a plugin, or by some smoke-and-mirrors so I can a) stop missing simple, stupid typos and b) get some auto-complete?
I think you're looking for the GroovyDSL scripting framework
http://confluence.jetbrains.net/display/GRVY/Scripting+IDE+for+DSL+awareness
its possible to save a *.gdsl file somethere in src dir, with content:
contributor(context()) {
def scope = com.intellij.psi.search.GlobalSearchScope.allScope(project);
delegatesTo(com.intellij.psi.JavaPsiFacade.getInstance(project).findClass('org.grails.datastore.gorm.GormStaticApi', scope)) delegatesTo(com.intellij.psi.JavaPsiFacade.getInstance(project).findClass('org.grails.datastore.gorm.GormEntity', scope))}

statically analysing Lua code for potential errors

I'm using a closed-source application that loads Lua scripts and allows some customization through modifying these scripts. Unfortunately that application is not very good at generating useful log output (all I get is 'script failed') if something goes wrong in one of the Lua scripts.
I realize that dynamic languages are pretty much resistant to static code analysis in the way C++ code can be analyzed for example.
I was hoping though, there would be a tool that runs through a Lua script and e.g. warns about variables that have not been defined in the context of a particular script.
Essentially what I'm looking for is a tool that for a script:
local a
print b
would output:
warning: script.lua(1): local 'a' is not used'
warning: script.lua(2): 'b' may not be defined'
It can only really be warnings for most things but that would still be useful! Does such a tool exist? Or maybe a Lua IDE with a feature like that build in?
Thanks, Chris
Automated static code analysis for Lua is not an easy task in general. However, for a limited set of practical problems it is quite doable.
Quick googling for "lua lint" yields these two tools: lua-checker and Lua lint.
You may want to roll your own tool for your specific needs however.
Metalua is one of the most powerful tools for static Lua code analysis. For example, please see metalint, the tool for global variable usage analysis.
Please do not hesitate to post your question on Metalua mailing list. People there are usually very helpful.
There is also lua-inspect, which is based on metalua that was already mentioned. I've integrated it into ZeroBrane Studio IDE, which generates an output very similar to what you'd expect. See this SO answer for details: https://stackoverflow.com/a/11789348/1442917.
For checking globals, see this lua-l posting. Checking locals is harder.
You need to find a parser for lua (should be available as open source) and use it to parse the script into a proper AST tree. Use that tree and a simple variable visibility tracker to find out when a variable is or isn't defined.
Usually the scoping rules are simple:
start with the top AST node and an empty scope
item look at the child statements for that node. Every variable declaration should be added in the current scope.
if a new scope is starting (for example via a { operator) create a new variable scope inheriting the variables in the current scope).
when a scope is ending (for example via } ) remove the current child variable scope and return to the parent.
Iterate carefully.
This will provide you with what variables are visible where inside the AST. You can use this information and if you also inspect the expressions AST nodes (read/write of variables) you can find out your information.
I just started using luacheck and it is excellent!
The first release was from 2015.

Resources