-
Instead of defining job property in build spec, you may define property
LABin sidebar menuSettings / Build / Job Properties. Also define job executor in parent project as@property:LAB@-docker-executor. This way you can override the LAB property as necessary in child projects, without changing build spec. -
Thank you for the replay. Using job property seems to be nice workaround. But having LAB as param (of emum type) allows me to make deployments to multiple labs at once. Maybe I could get this job property via groovy script and use it as build param?
-
Thank you for the replay. Using job property seems to be nice workaround. But having LAB as param (of emum type) allows me to make deployments to multiple labs at once. Maybe I could get this job property via groovy script and use it as build param?
I am confused. Seems that you are specifying choice values of LAB param to be a groovy script. You also want to read the LAB property in the groovy script. But choice values are expecting an array, while LAB property is a single value...
-
I was planning to read LAB property as a string with comma separated lab names, and return it splitted as an array from the script.
-
Try below groovy script:
import io.onedev.server.model.Project def labs = Project.get().getHierarchyJobProperties().find { it.name == 'LAB' }?.value return labs ? labs.split(/\s*,\s*/).toList() : []Property 'LAB' needs to be defined in project build settings taking comma separated values.
-
Thanks for the tips. I will try to make it working for me. Closing the question for now.
-
Previous Value Current Value Open
Closed
-
I was too fast with closing. I tried your snippet and got NPE. It looks like
Project.get()returned null:Caused by: java.lang.RuntimeException: Error evaluating groovy script:
def labs = Project.get().getHierarchyJobProperties().find { it.name == 'LAB' }?.value return labs ? labs.split(/\s*,\s*/).toList() : [] at io.onedev.server.util.GroovyUtils.evalScript(GroovyUtils.java:117) at io.onedev.server.util.GroovyUtils.evalScriptByName(GroovyUtils.java:89) ... 26 common frames omitted Caused by: java.lang.NullPointerException: Cannot invoke method getHierarchyJobProperties() on null object -
Previous Value Current Value Closed
Open
-
Works at my side. Can you please create sample projects at this site demonstrating the issue?
-
Works at my side. Can you please create sample projects at this site demonstrating the issue?
I can try, but I don't have access to page where scripts are defined. Maybe you could temporarily add this sample script you mentioned earlier, and I will use it in my sample project.
-
Added script
GetLabs -
Ok, I think I set it up correctly. Project is toomyem/test. Deploy buildspec is defined in parent project (toomyem), and imported in child (test). There is a trigger in parent which should run deploy on change in child. But when I commit a change in test, there is no new build. Probably because of the problem with null on
Project.get(), but I do not have access to logs on this system to confirm that. But this is happening on mine system. -
Thanks for demonstrating the issue. I ran the build from UI instead of pushing commit. The script currently can not access project object in that case. I filed an improvement request OD-2674, and close this now.
-
Previous Value Current Value Open
Closed
-
I tried to run the code provided in OD-2674, but sill getting NPE:
service-1 | Caused by: java.lang.RuntimeException: Error evaluating groovy script: service-1 | service-1 | import io.onedev.server.util.ProjectScopedCommit service-1 | service-1 | def project = ProjectScopedCommit.get().getProject() service-1 | def props = project.getHierarchyJobProperties() service-1 | def labs = props.find { it.name == 'LAB' }?.value service-1 | return labs ? labs.split(/\s*,\s*/).toList() : [] service-1 | at io.onedev.server.util.GroovyUtils.evalScript(GroovyUtils.java:117) service-1 | at io.onedev.server.util.GroovyUtils.evalScriptByName(GroovyUtils.java:89) service-1 | ... 31 common frames omitted service-1 | Caused by: java.lang.NullPointerException: Cannot invoke method getProject() on null object -
Previous Value Current Value Closed
Open
-
I'm running v14.0.7 by the way.
-
This improvement has been committed but not released yet.
-
Ah, I see 😃 So I will wait...
-
Previous Value Current Value Open
Closed
-
Build OD-7034 (14.0.8) is available contain fix of issue OD-2674 . To avoid confusion, the workflow at code.onedev.io is changed so that when an issue is closed, the release will also be available.
-
Thank you. It works fine for properties defined via Settings -> Build -> Job Properties. Any chance to extend it to Properties defined in .build-spec?
| Type |
Question
|
| Priority |
Normal
|
| Assignee | |
| Labels |
No labels
|
Is it possible to access buildspec's properties from groovy script?
I have a global deploy buildspec defined in parent repo, and need to parametrize it in child repos via properties (property LAB). I tried to access those properties from my
get_lab_valuescript, but without success.I tried to locate the relevant code and found this: https://code.onedev.io/onedev/server/~files/1d435bac543b41a8ca9c582fe765a30fd3d72904/server-core/src/main/java/io/onedev/server/job/DefaultJobService.java?position=source-776.1-794.53-1
There is a
nullpassed asParamCombinationtoresolveParams.Any chance to have it changed? 🥺