File tree 2 files changed +6
-11
lines changed
pipeline-examples/gitcommit
2 files changed +6
-11
lines changed Original file line number Diff line number Diff line change 1
1
# Synopsis
2
+
2
3
Demonstrate how to expose the git_commit to a Pipeline job.
3
4
4
5
# Background
5
6
6
7
The git plugin exposes some environment variables to a freestyle job that are not currently exposed to a Pipeline job.
7
- Here's how to recover that ability using a git command and Pipeline's readFile() function.
8
+ Here's how to recover that ability using a git command and Pipeline's [ ` sh ` ] [ pipeline-sh-documentation ] step.
9
+
10
+ [ pipeline-sh-documentation ] : https://jenkins.io/doc/pipeline/steps/workflow-durable-task-step/#sh-shell-script
Original file line number Diff line number Diff line change 2
2
// checked out your sources on the slave. A 'git' executable
3
3
// must be available.
4
4
// Most typical, if you're not cloning into a sub directory
5
- sh(' git rev-parse HEAD > GIT_COMMIT' )
6
- git_commit= readFile(' GIT_COMMIT' )
5
+ gitCommit = sh(returnStdout : true , script : ' git rev-parse HEAD' ). trim()
7
6
// short SHA, possibly better for chat notifications, etc.
8
- short_commit= git_commit. take(6 )
9
-
10
- // create a GIT_COMMIT file in workspace and read back into a string in Pipeline
11
- // If you have your sources checked out in a 'src' subdir
12
- sh(' cd src && git rev-parse HEAD > GIT_COMMIT' )
13
- git_commit= readFile(' src/GIT_COMMIT' )
14
- // short SHA, possibly better for chat notifications, etc.
15
- short_commit= git_commit. take(6 )
7
+ shortCommit = gitCommit. take(6 )
You can’t perform that action at this time.
0 commit comments