The metadata plugin was written in the "pre-pipeline job type era" (it is expecting AbstractProjects) and needs some work to be able to store metadata on pipeline jobs.
/B On Tue, Jan 3, 2017 at 8:53 PM, PF66 <[email protected]> wrote: > Tried to search how to do it, and have this issue: > > Noticed that I can't add Metadata to a Pipeline, and was pointed out on > IRC that MetadataJobProperty extends AbstractProject, while Pipeline > (WorkflowJob) doesn't extend it: > > stage 'testMetadata' > node{ > > def testJob = currentBuild; > properties([[$class :'MetadataJobProperty', > values : [[ > $class: 'StringMetadataValue', > name : 'owner', > value : 'bob' > ]] > ]]); > } > > This returns the error: ERROR: cannot apply com.sonyericsson.hudson. > plugins.metadata.model.MetadataJobProperty to a WorkflowJob > So is it possible to correct this? > > terça-feira, 3 de Janeiro de 2017 às 14:19:56 UTC, Tomas Westling escreveu: >> >> Yes, I would still do it like this. >> The rest api is meant to be used to control/query Jenkins from the >> outside of Jenkins, e.g. from other services that aren't running in Jenkins. >> If you are in groovy inside the Jenkins instance, it's sort of a detour >> to use the rest api. >> >> Look at e.g. the BuildContributorsController.onCompleted method and >> the StandardBuildMetadataContributor, it adds metadata to a build as it >> completes and do something similar in your script. >> >> Br Tomas >> >> On Tuesday, January 3, 2017 at 2:19:22 PM UTC+1, PF66 wrote: >>> >>> Thanks for the reply. >>> As Daniel Beck said, I got the answer yesterday and forgot to update >>> this thread. My mistake. >>> >>> Resolved by doing this: >>> >>> MetadataBuildAction metadataBuild = >>> Jenkins.getInstance().getItemByFullName(jobName, >>> Job.class).getBuildByNumber(buildNr).getAction(MetadataBuildAction.class); >>> >>> if(metadataBuild != null) { >>> Collection<String> metadataNames = metadataBuild.getChildNames(); >>> >>> >>> I'm sorry if it might seem trivial but since I'm fairly new to this, I >>> still have to catch all this little nuances. >>> >>> But still related, how can I do the 'update' of a value on a groovy >>> script inside a pipeline job? >>> I still need to access like this or do a cli/request? >>> >>> >>> terça-feira, 3 de Janeiro de 2017 às 09:45:24 UTC, Tomas Westling >>> escreveu: >>>> >>>> As Gavin says, if you want to read or manipulate the metadata from a >>>> plugin, you shouldn't use the rest api. >>>> For nodes, the metadata is stored as NodeProperties, look at >>>> MetadadataNodeProperty.java. >>>> For Jobs and Builds, look at the actions MetadataJobAction.java and >>>> MetadataBuildAction.java, these are available on jobs and builds >>>> that have metadata associated with them. >>>> >>>> Br Tomas >>>> >>>> Den söndag 1 januari 2017 kl. 17:59:49 UTC+1 skrev PF66: >>>>> >>>>> On the plugin there is a doGet() and doUpdate() ( >>>>> https://github.com/jenkinsci/metadata-plugin/blob/0a780cfd6 >>>>> ce11aba43bcd5e220bd3a318f0b33e9/src/main/java/com/sonyericss >>>>> on/hudson/plugins/metadata/cli/HttpCliRootAction.java) >>>>> >>>>> How can I call those inside my own plugin? I'm having trouble create >>>>> the StaplerRequest/Response and process them. >>>>> Maybe it isn't this the way to go? >>>>> >>>>> sábado, 31 de Dezembro de 2016 às 08:43:07 UTC, Gavin Mogan escreveu: >>>>>> >>>>>> Are you making a plugin to access data from another plugin using the >>>>>> rest API? >>>>>> >>>>>> I'm on mobile right now so I can't check but I'm pretty sure that >>>>>> plugin like most others will have actions (getActions()) attached to the >>>>>> build. Nothing exposed by rest should be hidden from native interfaces. >>>>>> >>>>>> If you are just writing a script, it belongs on the users list, but >>>>>> you'll need to create/reuse an existing user. All users will have >>>>>> username >>>>>> and API tokens on thier edit profile page, you should be able to use that >>>>>> to basic authenticate for APIs. >>>>>> >>>>>> Gavin >>>>>> >>>>>> -- > You received this message because you are subscribed to the Google Groups > "Jenkins Developers" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > To view this discussion on the web visit https://groups.google.com/d/ > msgid/jenkinsci-dev/d8306864-e156-425e-962b-3467dad93f23% > 40googlegroups.com > <https://groups.google.com/d/msgid/jenkinsci-dev/d8306864-e156-425e-962b-3467dad93f23%40googlegroups.com?utm_medium=email&utm_source=footer> > . > > For more options, visit https://groups.google.com/d/optout. > -- Robert Sandell *Software Engineer* *CloudBees Inc.* -- You received this message because you are subscribed to the Google Groups "Jenkins Developers" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-dev/CALzHZS0_KRhPd_LjuqcaLBCSDa2tBSXcFH3U6X6APXDA9sqK5A%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.
