2016-03-08 17 views
15

Đây là mã đường ống của tôi:Truy cập SCM (Git) biến trên một công việc Jenkins Pipeline

node ('master') { 
    git url: "$GIT_REPO_URL", branch: "$GIT_BRANCH" 
    echo env.GIT_COMMIT 
    echo env.GIT_BRANCH 
    echo env.GIT_REVISION 
} 

Việc xây dựng kết quả trông giống như:

Started by user anonymous 
[Pipeline] Allocate node : Start 
Running on master in /var/lib/jenkins/jobs/test/workspace 
[Pipeline] node { 
[Pipeline] git 
> git rev-parse --is-inside-work-tree # timeout=10 
Fetching changes from the remote Git repository 
> git config remote.origin.url https://acme/scm/app.git # timeout=10 
Fetching upstream changes from https://acme/scm/app.git 
> git --version # timeout=10 
> git fetch --tags --progress https://acme/scm/app.git +refs/heads/*:refs/remotes/origin/* 
> git rev-parse refs/remotes/origin/master^{commit} # timeout=10 
> git rev-parse refs/remotes/origin/origin/master^{commit} # timeout=10 
Checking out Revision fb455725db1b768ff63e627a087d2771099af7c4 (refs/remotes/origin/master) 
> git config core.sparsecheckout # timeout=10 
> git checkout -f fb455725db1b768ff63e627a087d2771099af7c4 # timeout=10 
> git branch -a -v --no-abbrev # timeout=10 
> git branch -D master # timeout=10 
> git checkout -b master fb455725db1b768ff63e627a087d2771099af7c4 
> git rev-list fb455725db1b768ff63e627a087d2771099af7c4 # timeout=10 
[Pipeline] echo 
null 
[Pipeline] echo 
null 
[Pipeline] echo 
null 
[Pipeline] } //node 
[Pipeline] Allocate node : End 
[Pipeline] End of Pipeline 
Finished: SUCCESS 

Các biến env env.GIT_COMMIT, env.GIT_BRANCH là không có dân cư. Các giá trị đó có sẵn trong các biến khác không?

Trả lời

13

Dưới đây là một ví dụ về cách bạn có thể nhận GIT_COMMIT - https://github.com/jenkinsci/pipeline-examples/blob/master/pipeline-examples/gitcommit/gitcommit.groovy

Bạn có thể mở rộng nó để lộ GIT_BRANCH là tốt. Kịch bản này là từ các ví dụ dòng công việc git repo được quản lý bởi cloudbees. Có lẽ bạn có thể gửi yêu cầu kéo nếu bạn thêm khả năng để truy lục biến GIT_BRANCH.

+13

Cảm ơn nhận xét của bạn. Tôi đã làm điều đó tuy nhiên tôi coi nó là một hack. ;) –

Các vấn đề liên quan