Jenkins console output is place where you can spend decent amount of time trying to figure out what went wrong (or perhaps right?).
AnsiColor plugins gives you opportunity to color monochromatic Jenkins console output.
1. Install AnsiColor plugin
Manage Jenkins > Manage Plugins > Available
> search and install ‘Ansi Color’
2. Configure your build/job
Under Build Environment section check Color ANSI Console Output and select xterm
3. Inside Execute shell step add something like:
echo "\033[1;33m[Info] \033[0m $1"
echo "\033[1;31m[Error] \033[0m $1"
echo "\033[1;32m[Success] \033[0m $1"
info "This is information message"
error "Houston we have a problem"
echo "Foreground colors"
echo "\033[31m Red \033[0m"
echo "\033[32m Green \033[0m"
echo "\033[33m Yellow \033[0m"
echo "\033[34m Blue \033[0m"
echo "\033[35m Magneta \033[0m"
echo "\033[36m Cyan \033[0m"
echo "Background colors"
echo "\033[41m Red \033[0m"
echo "\033[42m Green \033[0m"
echo "\033[43m Yellow \033[0m"
echo "\033[44m Blue \033[0m"
echo "\033[45m Magneta \033[0m"
echo "\033[46m Cyan \033[0m"
echo "Different combinations"
echo "\033[1;31m Red \033[0m"
echo "\033[1;4;37;42m Green \033[0m"
echo "\033[1;43m Yellow \033[0m"
4. On console output
Curl the URL to get the JSON response and pipe it to the python tool. The python code will extract the value mapped to the given key (number in this case).
buildnumber=$(curl --silent -X POST http://$machine:$machineport/job/$jobname/lastBuild/api/json?tree=number | python -c 'import json,sys;obj=json.load(sys.stdin);print obj["'number'"]';)
curl -X POST http://$machine:$machineport/job/$jobname/$number/stop
Note: the above command actually works
If you use virtualenv to isolate your python project’s environment, and want your code tested automatically — read on, else ignore.
virtualenv isolates your project’s python environment
virtualenv makes sure you lock down your project’s main directory and all subdirectories of it. This ‘lockdown’ means that you never touches your global python binary, or any globally installed libraries (like “sudo pip install ipython” ).
Once locked down, you install all packages again, even those you have globally installed. This enables you to have one version of flask globally installed, but another version in your project. All dependencies can be listed in a separate file and validate a precise environment for you to work with. Tightly controlled dependencies is key to a deployment without surprises.
Jenkins checks the health of your project for each change
Jenkins is a CI server which means it does a lot of repeating stuff so you can focus on doing more important stuff. More specifically, it listens for changes to your project’s version control system (like git).
When changes are detected, the project is built and the test suite is executed. If any step fails, the CI server tells you that it did.
Setup Jenkins, and make it use virtualenv
Jenkins needs some massaging before it handles the hijacked environment of virtualenv. This is how I did it for my local git repository:
- Download and install Jenkins
- Start it, it should be up on http://localhost:8080
- Install the Git Plugin
- Setup a new project with these properties:
- Source Code Management: add the URI to your local repository,
- /Users/you/Sites/asdf in my case. Make sure the jenkins user can read this directory, otherwise the Jenkins GUI will tell you something random about invalid git repo, without a hint about a permissions error.
- Build Triggers: Poll SCM (with an interval like 0 * * * *). This is needed because
you’re too lazy to build manually; and
you can not trigger builds with a git post-commit hook otherwise
- Build > Execute shell. I’ve used two steps, one for setting up the environment and one for the actual tests:
# Setup a proper path, I call my virtualenv dir "venv" and
# I've got the virtualenv command installed in /usr/local/bin
if [ ! -d "venv" ]; then
pip install -r requirements.txt --download-cache=/tmp/$JOB_NAME
# reply should be