0
votes

From version 0.33.1 onwards, aws-sam-cli supports colored output. I'm trying to run the sam deploy command from Jenkins pipeline and the output is not displaying in colored format. I've installed ANSIColor Jenkins plugin and wrapped the sam deploy command with ansiColor('xterm') {}. The command works as expected and the Cloudformation stack is getting created. The concern is the output is not in colored format.

node {
stage('Example') {
    ansiColor('xterm') {
        sh "sam deploy --parameter-overrides ${someparameter} --template-file ${templatefile} --stack-name ${stackname} --capabilities CAPABILITY_NAMED_IAM  --no-fail-on-empty-changeset --no-execute-changeset"
   }
 }
}

In order to verify my Jenkins, I tried test-snippet in Jenkins and it displayed the colored output.

ansiColor('xterm') {
    stage "\u001B[31mI'm Red\u001B[0m Now not"
}

enter image description here

So Jenkins is able to display ANSI color, but the aws-sam-cli output is not in colored format.

Any ideas or pointers would be helpful.

1

1 Answers

1
votes

aws-sam-cli uses click library to format its output, including color handling.

The documentation for click explains why you're seeing what you're seeing:

Starting with Click 2.0, the echo() function gained extra functionality to deal with ANSI colors and styles. [...]

Primarily this means that:

  • Click’s echo() function will automatically strip ANSI color codes if the stream is not connected to a terminal.

This is a typical behavior of most programs, however some programs allow overriding this, usually with --color parameter.

In your case, I'd suggest asking for an enhancement on click's issue tracker.

Edit: There's already been one.