File tree Expand file tree Collapse file tree 2 files changed +6
-11
lines changed
pipeline-examples/gitcommit Expand file tree Collapse file tree 2 files changed +6
-11
lines changed Original file line number Diff line number Diff line change 11# Synopsis
2+
23Demonstrate how to expose the git_commit to a Pipeline job.
34
45# Background
56
67The 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 22// checked out your sources on the slave. A 'git' executable
33// must be available.
44// 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()
76// 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