Hi,

Have you got the solution? I am looking for similar feasibility.




On Wednesday, April 15, 2015 at 7:24:46 PM UTC+5:30, Varal wrote:
>
> Hey everyone,
>
> For the past 2 days I've been struggling with the following issue:
> I have a few jobs whose builds are promoted to "Latest" when certain 
> requirements are met. Once a night I would like to run a 
> "Promote_to_nightly" job which runs regression, coverity and other tests 
> against these promoted to "Latest" builds across different jobs. If 
> everything ends well the "Promote_to_nightly" job should trigger a 
> promotion called "Nightly" on the "Latest" build. At the end of it all I 
> should have jobs A B C D with builds that are promoted both to "Latest" and 
> "Nightly". 
>
> The promotion is done by defining a "Nightly" promotion in each job 
> configuration with the "Only when manually approved" option ticked and 
> running the approve() method which can be found 
> in hudson.plugins.promoted_builds.conditions.ManualCondition.java
>
> I managed to write a groovy script that does the promotion but it has a 
> side effect. The builds get promoted and an "Unknown Task" is displayed in 
> the build queue and Jenkins error log shows the following message:
>
> java.lang.IllegalStateException: no parent set on hudson.plugins.
> promoted_builds.PromotionProcess[Nightly]
>  at hudson.model.AbstractItem.getParent(AbstractItem.java:179)
>  at hudson.plugins.promoted_builds.PromotionProcess.getParent(
> PromotionProcess.java:140)
>  at hudson.plugins.promoted_builds.PromotionProcess.getOwner(
> PromotionProcess.java:148)
>  at hudson.plugins.promoted_builds.PromotionProcess.getAssignedLabel(
> PromotionProcess.java:195)
>  at hudson.model.Queue$Item.getAssignedLabel(Queue.java:1415)
>  at hudson.model.Node.canTake(Node.java:330)
>  at hudson.model.Queue$JobOffer.canTake(Queue.java:277)
>  at hudson.model.Queue.maintain(Queue.java:1049)
>  at hudson.model.Queue$MaintainTask.doRun(Queue.java:2048)
>  at hudson.triggers.SafeTimerTask.run(SafeTimerTask.java:54)
>  at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471
> )
>  at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:304)
>  at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.
> access$301(ScheduledThreadPoolExecutor.java:178)
>  at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.
> run(ScheduledThreadPoolExecutor.java:293)
>  at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.
> java:1145)
>  at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.
> java:615)
>  at java.lang.Thread.run(Thread.java:745)
>
> The code I'm using (only the needed part from my testing) is as follows:
>
> import hudson.model.*
> import hudson.model.ItemGroup
> import hudson.scm.*
> import java.util.*
> import hudson.plugins.promoted_builds.*
> import hudson.plugins.promoted_builds.conditions.*
>
> println "RUNNING NIGHTLY PROMOTION GROOVY SCRIPT"
>   
> //These are the jobs that are under the "Nightly" promotion process
> def jobsToPromote = [Hudson.instance.getJob("Test_job")]
>
> //Object for the nightly promotion
> PromotionProcess nightlyPromotion = new 
> PromotionProcess(jobsToPromote[0].getParent(), "Nightly")
>
> //Object for the manual approval of the nightly promotion
> ManualCondition manualPromotion = new ManualCondition()
>
> //Array for storing builds promoted to "Latest"
> def jobBuildsToPromote = []
>
> //Get builds of Jobs promoted to "Latest" and store them in 
> jobBuildsToPromote array
> jobsToPromote.each { job -> (job.getBuilds()).find
>   {
>                build -> (build.getActions(PromotedBuildAction)).find
>     {
>       action -> if(action.contains("Latest"))
>       {
>         jobBuildsToPromote.add(build)
>         return true
>       }
>     }
>   }
> }
>
> manualPromotion.approve(jobBuildsToPromote[0], nightlyPromotion)
>
>
> //Function for reading environment variables
> def getBuildVariable(String key)
> {
> def config = new HashMap()
> def thr = Thread.currentThread()
> def build = thr?.executable
> def envVarsMap = build.parent.builds[0].properties.get("envVars")
>
> config.putAll(envVarsMap)
> return config.get(key)
> }
>
> return
>
>
> Does anyone have an idea how to solve this issue?
> Many thanks in advance for all your suggestions :)
>
>

-- 
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/c2c5a69d-5439-42d8-b6dd-401974db4922%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to