How can I write to stdout to create a foldable output log in gocd?

140 Views Asked by At

I have a local gocd instance running, but I would like to more directly target my logs to have folding inline.

When gocd starts a task, it wraps it in a foldable element starting with

[go] Task:

And then all of the task content is folded under this.

I'm familiar with doing the same thing that I'm asking for here in TeamCity using Service Messages, such as:

##teamcity[blockOpened name='<blockName>' description='<this is the description of blockName>']

... Do some stuff, and you would resolve at the end of the block with this next line ...

##teamcity[blockClosed name='<blockName>']

I am having trouble locating any documentation that indicates if gocd has similar service messages, and it may not. I see references in several gocd issues, such as this one: https://github.com/gocd/gocd/issues/873, that indicate that they may have created functionality to make this easy to consume.

1

There are 1 best solutions below

0
Mashikur Rahman Mirash On

To achieve foldable inline logs in GoCD similar to the way it's done with TeamCity's Service Messages, you can use GoCD's log formatting syntax. While GoCD doesn't have the exact equivalent of Service Messages, you can achieve folding using the following approach:

  1. Use ##[fold] to start a foldable section in your log.
  2. Place your task commands and log messages within this foldable section.
  3. Use ##[endfold] to close the foldable section.

Here's an example of how you can use this approach in your GoCD pipeline task:

#!/bin/bash

echo "##[fold]Task: Your Task Name"
# Your task commands here
echo "This is a log message inside the foldable section."
# More task commands
echo "##[endfold]"

Replace "Your Task Name" with the name you want to give to the foldable section. The content within the ##[fold] and ##[endfold] tags will be collapsible in the log output.