How to get commit date and time on GitLab CI

前端 未结 2 1637
遥遥无期
遥遥无期 2021-02-09 23:25

Actually I have a need to get a timestamp of my commit in GitLab CI. Alredy have tested the official documentation of GitLab CI Variables here: https://docs.gitlab.com/ee/ci/var

相关标签:
2条回答
  • 2021-02-09 23:40

    Yes you can get the commit time, like this:

    job:
      script: 
        - export COMMIT_TIME=$(git show -s --format=%ct $CI_COMMIT_SHA)
        - echo $COMMIT_TIME
    

    If you want to have your COMMIT_TIME variable in every job use the before_script option:

    before_script:
      - export COMMIT_TIME=$(git show -s --format=%ct $CI_COMMIT_SHA)   
    
    job:
      script: 
        - echo $COMMIT_TIME
    

    The %ct format gives you unixtimestamp if you want something else, have a look at the PRETTY_FORMATS in this reference on git show.

    0 讨论(0)
  • 2021-02-09 23:51

    From GitLab 13.4 you can use a new predefined variable for this: CI_COMMIT_TIMESTAMP

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