Jenkins - groovy script - get last successful build date in dd-mm-yyyy format

前端 未结 1 714
迷失自我
迷失自我 2021-02-15 13:02

I\'m using \"groovy script\" plugin as part of my Jenkins build. I wish to find the last successful build date of a job \"RegularBuild\" however all the examples online e.g.

相关标签:
1条回答
  • 2021-02-15 13:13

    Following sample will help you. I generally find it useful to setup a plugin development environment and see the actual Types and check documentation

    import jenkins.model.Jenkins
    
    def item = Jenkins.instance.getItem("your-job-name")
    def  f=item.getLastFailedBuild()
    
    println f.getTime()
    
    
    
    def  ff=item.getLastSuccessfulBuild()
    println ff.getTime().format("YYYY-MMM-dd HH:mm:ss")
    println ff.getTime().format("dd-MM-yyyy")
    

    Edit

    (From comments of @Steven the Easily Amused ) If the Jenkins uses folders , then you need getItemByFullName("/folder/yourjobname")

    Edit 2

    Fix date/time format s/MM:SS/mm:ss/ (substitute digits-of-month:milliseconds with minutes:seconds)

    0 讨论(0)
提交回复
热议问题