Search code examples
jenkinspipeline

How to get Epoch(unix) timestamp in Jenkins declarative pipeline code


im working on Jenkins to automate my test runs in my project and as a task/stage where i need to fetch or use epoch timestamp in stage. Could you please help me with your suggestions how can i achieve it?

Required Format: 1656166890987


Solution

  • You can simply do the following.

    steps {
           script {
              def time = new Date().getTime()
              echo "$time"
          }
    }