I'm making a change to a Jenkins plugin (https://wiki.jenkins-ci.org/display/JENKINS/Stash+pullrequest+builder+plugin), as I would like to add a couple of options to it.
However, having added two new checkboxes to the config.jelly, they don't appear to work correctly in the job config through the GUI.
config.jelly:
<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:d="jelly:define" xmlns:l="/lib/layout" xmlns:t="/lib/hudson" xmlns:f="/lib/form">
...
<f:advanced>
...
<f:entry title="Report build started to Stash?" field="reportBuildStartedToStash">
<f:checkbox default="true"/>
</f:entry>
<f:entry title="Report build result to Stash?" field="reportBuildStatusToStash">
<f:checkbox default="true"/>
</f:advanced>
</j:jelly>
If I add this plugin to a job like so:
Then the two checkboxes default to "true" as expected. This is reflected in the config.xml:
<triggers>
<stashpullrequestbuilder.stashpullrequestbuilder.StashBuildTrigger plugin="stash-pullrequest-builder#1.3.1-SNAPSHOT">
...
<reportBuildStartedToStash>true</reportBuildStartedToStash>
<reportBuildStatusToStash>true</reportBuildStatusToStash>
</stashpullrequestbuilder.stashpullrequestbuilder.StashBuildTrigger>
</triggers>
However, if I untick these checkboxes, save the changes, and reload the Job Configuration page, the checkboxes will appear to be ticked again.
Could this be a problem with my .jelly config? I can't understand how or why.
For reference, my branch is here: https://github.com/blaffoy/stash-pullrequest-builder-plugin/tree/optional-messages-to-stash
This issue appears to be same as raised here, but the solution suggested doesn't fix the problem for me. That is, to replace <f:checkbox default="true"/> with <f:checkbox/>
This will work by prefixing the getter methods in StashBuildTrigger.java with "is" e.g.
public boolean isReportBuildStartedToStash()
public boolean isDeleteBuildStartedToStash()
public boolean isReportBuildStatusToStash()
I think this would also work with a "get" prefix but I havent tested it. As per the jenkins plugin doc:
Define getters for the configuration fields, or make the fields
"public final". This allows Jelly script to read the values to
populate the configuration page.
A few things to notice: the 'get' was automatically stripped from the
method name, and the first letter of the remaining method name was
lower-cased. I'd recommend using the Java convention for naming
methods (e.g. starting getters with 'get' and using CamelCase) so that
Jelly can always find the methods.
Example java naming conventions:
Use the prefixes get and set for getter and setter methods. ... If the
method returns a boolean value, use is or has as the prefix for the
method name.
Related
I'm writing descriptors for somebody else's pipeline steps jenkins plugin. Most steps are straight forward, e.g.
mySimpleStep(param1: value1, param2: value2)
However one of the steps requires a parameter, which is a map of two other values, so the actual call syntax is the following:
myOtherStep(param1: value1, param2: [sub1: value2, sub2: value3])
I can't fathom how to specify the parameters in the config.jelly file for the step and/or update the actual Step class so that the call syntax is created correctly. How can I do that?
(param2 class does have its own #DataBoundConstructor if it matter)
Do note that this is somebody else's plugin, I am in no position to change the actual plugin.
After almost giving up, I stumbled upon the answer while looking at the source code of Microsoft Azure Storage plugin. Here are the steps I needed to do.
Ensure that the class of param2 implements Step and add Description inner class to it. It also needs to have a #DataBoundConstructor
Create a separate descriptor directory for the class in resources with its own config.jelly and help-*.html files
Change the config.jelly of myOtherStep to have something like this:
<f:section title="General">
<f:entry field="value1" title="First param" description="Simple parameter">
<f:textbox/>
</f:entry>
<f:property field="value2">
<st:include page="config.jelly"/>
</f:property>
</f:section>
Now the config.jelly class for the complex parameter will be included - and everything works as expected.
simple question for you..
I have a property file with a value like this
CommercialManager=MOT
CommercialUser=AT
CommercialAdmin=POT
I'm calling an Ant Script from Jenkins, passing some variables..
some of these variables are used to get a dynamic property from the property file..
I'm saying that if i select into the jenkins job the CommercialAdmin variable from a select list i want to get the property with that name.
The value selected into the Jenkins JOB is set inside a variable ROLE, that is passed to my ANT script..
Below my code:
<property file="Profiles.properties" prefix="profiles"/>
<echo>${profiles.CommercialManager}</echo>
Doing like this everything works fine, it prints out
MOT
But as you can see the value is not dynamic, is not the one taken from jenkins job..
So i should do something like this:
<echo>${ROLE}</echo>
But if I do something like this, the print returns the value of the property ROLE that is:
profiles.CommercialManager
and not the value taken from the properties file..
How can i manage this? I think its easy but, its late, and i swimming into a sea of confusion..
Thanks a lot!
There are a number of ways to dynamically get a property value from a variable described in other threads:
In Ant, how can I dynamically build a property that references a property file?
Dynamic property names in ant
Personally, I would use javascript:
<property file="Profiles.properties" prefix="profiles"/>
<script language="javascript"><![CDATA[
project.setProperty("CommercialManager", project.getProperty("${Role}"))
]]>
</script>
<echo>${CommercialManager}</echo>
I'm using jenkins to build an ant project.
The target names in the build.xml are too verbose.
How can I give the target a more user-friendly name?
For example:
I want to change server_remote_stop to "Stop Server", and server_remote_start to "Start Server" without modifying the target names in build.xml (because this build.xml is used by other programs).
Is this possible?
Yes, it is possible, but you will need to use a different Active Choices parameter type: Reactive Reference Parameter.
Here are the settings that I used:
One active choices parameter named PARAMETER1 with some random server names (AAA, BBB)
One active choices reactive reference parameter, that is watching PARAMETER1, has Choice type as "Formatted HTML", has the Advanced option "Omit value" checked, and the following script:
html ="""
Start Server $PARAMETER1
Stop Server $PARAMETER1
"""
This kind of Formatted HTML is rendered in the UI as HTML, and you can mimic HTML components used in Jenkins, like a select box (you can use a radio, checkbox, etc). What is important is that you return some element whose name is "value" and omit the value field that is automatically created by the plugin (thus the advanced option Omit Value).
Since it is a reactive parameter, you can reference other parameters in your Groovy script as well :-)
Hope that helps,
Bruno
I'm building a very basic app using Grails 3.0.2.
I have a domain class called Unit which contains, among others, a field called season, whose type is Integer and represents a year.
I have used the command generate-views to generate the scaffolded views.
Once running the application, when an existing instance is shown, the season is displayed using "," as thousands separator, and I want to remove it.
What is the easiest way to override (only) the format of the season?
For testing purposes, I have modified the show.gsp of the Unit class in the following manner:
<f:with bean="unit">
<f:display />
<f:display property="season" />
</f:with>
The <f:display property="season" /> displays simply "1,975", but ignores the label.
I've tried to understand the documentation of the Fields plugin, but I do not achieve what I want so it's obvious that I do not understand it.
I have added _displayWidget.gsp under views/_fields/unit/season (I have also tried under views/unit/season), but the outcome is exactly the same than before, so I assume the plugin is not taking them into account.
<g:formatNumber groupingUsed="false" number="${value}" />
I am not familiar with the _displayWidget.gsp convention, but a simpler approach might be to override the display of the unit.season property by adding a _display.gsp under views/_fields/unit/season containing just the following:
${value}
Diego, you can format any given number using the taglib formatNumber:
https://grails.github.io/grails-doc/latest/ref/Tags/formatNumber.html
Use the param 'format' and check the DecimalFormat patterns to find the one that suits fine for you.
Hope it helps!
I was able to get this working in Grails 3.1.14 by creating views/_fields/myDomainClass/myFieldName/_displayWrapper.gsp and containing a single line of ${value}
What seems to me to be a common requirement for database changes, is the addition of a column that can't be null. One way round the problem of populating this column in some circumstances would be to define it as 'not null with default' in the DDL.
Grails doesn't appear to support 'NNWD' directly in constraints. I tested an idea that seems to work as an equivalent:
String name = default
...
name nullable:false
I wondered if dbm-gorm-diff changleog-n.xml would be able to detect this as being a null with a default. But it didn't. That's with version 1.2.2. I see that Liquibase supports this via its <addNotNullConstraint.
Are there any plans to introduce this support? Any suggestions as to how I might work round this, perhaps via a user-written script that makes use of dbm scripts.
Problem:
I tried using 1.3.2, but I get a MissingMethodException when running the script. The actual error line is:
groovy.lang.MissingMethodException: No signature of method: static grails.plugin.databasemigration.ScriptUtils.executeAndWrite() is applicable for argument types: (java.lang.String, java.lang.Boolean, DbmGormDiff$_run_closure1_closure2) values: [changelog-with-data.xml, false, DbmGormDiff$_run_closure1_closure2#2f673724]
Which I don't understand since the args seem to match the signature of the executeAndWrite() method in the plugin's code.
Regards, John
I have done some investigation on this topic and realised that the solution is more complicated, and trying to solve by adding a column using 'not null with default' is not the way to go. As I am planning to use Liquibase and Ant to update the database in test, uat and live environments, I refer to using xml files below.
If the table doesn't have any data, then you can add a column that is 'not null'. This seems to me to be an unlikely situation for a live database.
When the table contains data a new column must be defined as null. There is 3-step process, which requires manual updates to the xml file generated by the plugin:
define the new domain attribute as 'nullable:true', and generate the diff xml file.
update the xml file to add a new changeset using the < SQL> tag:
< sql>update [table] set [column]='dflt value' where [column] is null< /sql>
Now you can define the new column as not-null. Could use more raw sql, or look up Liquibase's < addNotNullConstraint>.
I don't think there is really a need for a default value for the column, since Grails will ensure that nulls don't get through from the browser. I say this since I haven't found a way to alter the definition of the added column so it has a default value.
John
If you're using 1.4.0 version of plugin it doesn't generate the changelog xmls for default values but you can edit the generated files to add the defaultValue & value attributes where it'll add the non-null columns without errors by updating the existing records with the value attribute.
Here's a small example for what it'd look like after modification:
<changeSet author="anybody (generated)" id="1467324956xxx-xx">
<addColumn tableName="table1">
<column name="col1" type="varchar(10)" defaultValue="value1" value="value1">
<constraints nullable="false"/>
</column>
</addColumn>
</changeSet>
More info you can find on liquibase docs http://www.liquibase.org/documentation/column.html
http://www.liquibase.org/documentation/changes/add_column.html