Parse what is possibly invalid JSON with JQ
echo "not json" | jq -R '. as $line | try (fromjson) catch $line
# > "not json"
echo "not json" | jq -R '. as $line | try (fromjson) catch $line
# > "not json"
Especially punitive when working with includes from local files or external components, if you have a job that is running for different environments (say staging and production), with the given component:
# my-component.yml
spec:
inputs:
environment:
type: string
---
do-something:
script:
- echo $[[ inputs.environment ]]
the following .gitlab-ci.yml
# .gitlab-ci.yaml
include:
- component: $CI_SERVER_FQDN/my-project/my-component@1.0.0
inputs:
environment: staging
- component: $CI_SERVER_FQDN/my-project/my-component@1.0.0
inputs:
environment: production
will be compiled to
do-something:
script:
- echo "production"
because the key do-something is duplicated across instanciations of the component.
A solution to this is adding the environment key to the name of the job:
# my-component.yml
spec:
inputs:
environment:
type: string
---
do-something:$[[ inputs.environment ]]:
script:
- echo $[[ inputs.environment ]]
Terminal emulators like AlacriTTY, WezTerm or Rio (I use Tilix on Ubuntu) can usually display an alternate screen that replaces the normal prompt. This is particularly useful for TUI applications like Tig or dive, which will use the entire terminal screen. When exited, the state of the terminal session will not have been discarded and you'll be able to keep doing whatever you were doing before!