Provide GIT_COMMIT_TITLE as environment variable
JENKINS-52490 - Provide GIT_COMMIT_TITLE as environment variable
Updated the pull request by Jeff Krunek . Fixed the test case testCommitMessageisEnvVar to directly run the freestyle job so the checkout step is automatically initiated and setting up the GIT_COMMIT_TITLE environment variable in the buildEnvironment API instead of the checkout step.
Checklist
- [x] I have read the CONTRIBUTING doc
- [x] I have referenced the Jira issue related to my changes in one or more commit messages
- [x] I have added tests that verify my changes
- [x] Unit tests pass locally with my changes
- [ ] I have added documentation as necessary
- [x] No Javadoc warnings were introduced with my changes
- [x] No spotbugs warnings were introduced with my changes
- [ ] Online help has been added and reviewed for any new or modified fields
- [x] I have interactively tested my changes
- [x] Any dependent changes have been merged and published in upstream modules (like git-client-plugin)
Types of changes
- [x] Bug fix (non-breaking change which fixes an issue)
Further Comments
As CaptureEnvironmentBuilder does not capture the environment variable GIT_COMMIT_TITLE if populated in the checkout step. Other variables like GIT_BRANCH and GIT_COMMIT are captured by the CaptureEnvironmentBuilder as they are populated in the buildEnvironment API as well, but GIT_COMMIT_TITLE can not be populated so implemented it in buildEnvironment API.
I wonder when this pr can be merged, it's been a long time...
I would recommend caution here - as per the ant /maven / multiple levels inside pipeline plugin and many other places where untrusted data has made its way into environment variables and then escaping it becomes a necessity for anyone wishing to consume it. (maven/ant PR titles for example in the scm-api, esp when any safeness needs to be multi level of scripts).
if this is needed then it would seem beneficial to those that want this to obtain it directly the checkout themselves (git log -1 --format=format:%s HEAD) and not from the environment.