Skip to content

Instantly share code, notes, and snippets.

@om3rcitak
Last active April 18, 2020 20:14
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save om3rcitak/f48a96cf3c8519a1de0eaf181dcf5bf5 to your computer and use it in GitHub Desktop.
Save om3rcitak/f48a96cf3c8519a1de0eaf181dcf5bf5 to your computer and use it in GitHub Desktop.
Jenkins Laravel Artisan Commands in GIT Commit Message

Jenkins Laravel Artisan Commands in GIT Commit Message

Code Snippet

How to use?

Jenkins Configuration

  1. Create a new Job or Pipeline.
  2. Go to "Build" tab.
  3. Add build step > Execute shell
  4. Paste code in the script.sh to "Command" area.

Jenkins Configuration

Write Artisan commands in GIT commit message

Write all Artisan command in the GIT commit message with --artisan- prefix.

Example:

$ git commit -m "jenkins artisan test --artisan-cache:clear --artisan-migrate --artisan-db:seed"

Jenkins build console log after example git commit message;

Jenkins Build Output

#!/bin/bash
LATEST_COMMIT_MESSAGE="$(git log --oneline --format=%B -1)"
while IFS=' ' read -ra part; do
for i in ${part[@]}; do
if [[ $i =~ "--artisan" ]]; then
command="php artisan ${i:10}"
echo "> ${command}"
$command
fi
done
done <<< $LATEST_COMMIT_MESSAGE
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment