How to get build time stamp from Jenkins build variables?

前端 未结 10 932
余生分开走
余生分开走 2020-12-24 11:25

How can I get build time stamp of the latest build from Jenkins? I want to insert this value in the Email subject in post build actions.

相关标签:
10条回答
  • 2020-12-24 12:14

    Try use Build Timestamp Plugin and use BUILD_TIMESTAMP variable.

    0 讨论(0)
  • 2020-12-24 12:17

    I know its late replying to this question, but I have recently found a better solution to this problem without installing any plugin. We can create a formatted version number and can then use the variable created to display the build date/time. Steps to create: Build Environment --> Create a formatted version number:

    • Environment Variable Name: BUILD_DATE

    • Version Number Format String: ${BUILD_DATE_FORMATTED}

    thats it. Just use the variable created above in the email subject line as ${ENV, var="BUILD_DATE"} and you will get the date/time of the current build.

    0 讨论(0)
  • 2020-12-24 12:17

    If you want add a timestamp to every request from browser to jenkins server. You can refer to the jenkins crumb issuer mechanism, and you can hack the /scripts/hudson-behavior.js add modify here. so it will transform a timestamp to server.

        /**
         * Puts a hidden input field to the form so that the form submission will have the crumb value
         */
        appendToForm : function(form) {
            // add here. ..... you code
            if(this.fieldName==null)    return; // noop
            var div = document.createElement("div");
            div.innerHTML = "<input type=hidden name='"+this.fieldName+"' value='"+this.value+"'>";
            form.appendChild(div);
        }
    
    0 讨论(0)
  • 2020-12-24 12:17

    You can use the Jenkins object to fetch the start time directly

    Jenkins.getInstance().getItemByFullName(<your_job_name>).getBuildByNumber(<your_build_number>).getTime()
    

    also answered it here: https://stackoverflow.com/a/63074829/1968948

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