How to persist data in BuildStep's perform method?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

How to persist data in BuildStep's perform method?

司芳源

In my builder class I have a Integer field, which will increase by 1 in the perform method. I tested it, this field did increase after each build as expected. However, after jenkins reboot, this field returned to its initial value, because its value is not changed in the job's config.xml. I don't know how jenkins remembered this field's last state when running(maybe in memory?).

My question is how can I persist the change in the job's config.xml? So that I'll not lose the change even after jenkins reboot?

--
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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-dev/12fc6bba-7d43-467c-8b53-5195badecda5%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: How to persist data in BuildStep's perform method?

Robert Sandell-2
You add an action to the build or the job.

/B

2017-12-01 4:31 GMT+01:00 司芳源 <[hidden email]>:

In my builder class I have a Integer field, which will increase by 1 in the perform method. I tested it, this field did increase after each build as expected. However, after jenkins reboot, this field returned to its initial value, because its value is not changed in the job's config.xml. I don't know how jenkins remembered this field's last state when running(maybe in memory?).

My question is how can I persist the change in the job's config.xml? So that I'll not lose the change even after jenkins reboot?

--
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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-dev/12fc6bba-7d43-467c-8b53-5195badecda5%40googlegroups.com.
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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-dev/CALzHZS38yzvC3YK-Hm6yF8dAZyOFs91Wk-392KwjURCZe40nBQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: How to persist data in BuildStep's perform method?

司芳源
Hi Robert, the link you gave describes how to add an action to a build. but I can't store this field in a build's action, because I might lose track of this field. For example, if a build fails before it gets to my plugin, or at some time the user decides to delete all previous build.

So it's better to store this field at the project's level, whose value may(or may not) change over each build. 

Does "the job" in your answer means "project"? If so, How do you add action to a project and change it over build?
 
On Friday, December 1, 2017 at 7:23:53 PM UTC+8, Robert Sandell wrote:
You add an action to the build or the job.
<a onmousedown="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fjenkins.io%2Fdoc%2Fdeveloper%2Ftutorial%2Fextend%2F\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNFmlsdGS38bA0CQg8dLa0Hd9P8xVg&#39;;return true;" onclick="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fjenkins.io%2Fdoc%2Fdeveloper%2Ftutorial%2Fextend%2F\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNFmlsdGS38bA0CQg8dLa0Hd9P8xVg&#39;;return true;" href="https://jenkins.io/doc/developer/tutorial/extend/" target="_blank" rel="nofollow">https://jenkins.io/doc/developer/tutorial/extend/

/B

2017-12-01 4:31 GMT+01:00 司芳源 <<a onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;" href="javascript:" target="_blank" rel="nofollow" gdf-obfuscated-mailto="ir9MuSGABQAJ">sify...@...>:

In my builder class I have a Integer field, which will increase by 1 in the perform method. I tested it, this field did increase after each build as expected. However, after jenkins reboot, this field returned to its initial value, because its value is not changed in the job's config.xml. I don't know how jenkins remembered this field's last state when running(maybe in memory?).

My question is how can I persist the change in the job's config.xml? So that I'll not lose the change even after jenkins reboot?

--
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 <a onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;" href="javascript:" target="_blank" rel="nofollow" gdf-obfuscated-mailto="ir9MuSGABQAJ">jenkinsci-de...@googlegroups.com.
To view this discussion on the web visit <a onmousedown="this.href=&#39;https://groups.google.com/d/msgid/jenkinsci-dev/12fc6bba-7d43-467c-8b53-5195badecda5%40googlegroups.com?utm_medium\x3demail\x26utm_source\x3dfooter&#39;;return true;" onclick="this.href=&#39;https://groups.google.com/d/msgid/jenkinsci-dev/12fc6bba-7d43-467c-8b53-5195badecda5%40googlegroups.com?utm_medium\x3demail\x26utm_source\x3dfooter&#39;;return true;" href="https://groups.google.com/d/msgid/jenkinsci-dev/12fc6bba-7d43-467c-8b53-5195badecda5%40googlegroups.com?utm_medium=email&amp;utm_source=footer" target="_blank" rel="nofollow">https://groups.google.com/d/msgid/jenkinsci-dev/12fc6bba-7d43-467c-8b53-5195badecda5%40googlegroups.com.
For more options, visit <a onmousedown="this.href=&#39;https://groups.google.com/d/optout&#39;;return true;" onclick="this.href=&#39;https://groups.google.com/d/optout&#39;;return true;" href="https://groups.google.com/d/optout" target="_blank" rel="nofollow">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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-dev/72ff46df-ba8d-405d-a9d5-f240ec85e6ef%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: How to persist data in BuildStep's perform method?

Robert Sandell-2
Both Run (the base class for most build types) and Job (the base class for most Project types) implements Actionable which is the base class for anything that can store Actions.

/B

2017-12-02 13:34 GMT+01:00 司芳源 <[hidden email]>:
Hi Robert, the link you gave describes how to add an action to a build. but I can't store this field in a build's action, because I might lose track of this field. For example, if a build fails before it gets to my plugin, or at some time the user decides to delete all previous build.

So it's better to store this field at the project's level, whose value may(or may not) change over each build. 

Does "the job" in your answer means "project"? If so, How do you add action to a project and change it over build?
 
On Friday, December 1, 2017 at 7:23:53 PM UTC+8, Robert Sandell wrote:
You add an action to the build or the job.

/B

2017-12-01 4:31 GMT+01:00 司芳源 <[hidden email]>:

In my builder class I have a Integer field, which will increase by 1 in the perform method. I tested it, this field did increase after each build as expected. However, after jenkins reboot, this field returned to its initial value, because its value is not changed in the job's config.xml. I don't know how jenkins remembered this field's last state when running(maybe in memory?).

My question is how can I persist the change in the job's config.xml? So that I'll not lose the change even after jenkins reboot?

--
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 jenkinsci-de...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-dev/12fc6bba-7d43-467c-8b53-5195badecda5%40googlegroups.com.
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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-dev/72ff46df-ba8d-405d-a9d5-f240ec85e6ef%40googlegroups.com.

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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-dev/CALzHZS3%3De0R9a9KWdioj_HBkrJNYb1-E35xb%2Bj%3D40_boy87uZA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.