Should I quote Strings in YAML?

Should I or should I not? Is it required? Will it work even without quotes – single or double?

ANSWER

I’ve asked myself these questions several times. Often I end up double-quoting long strings, but not for one word ones or shorter strings. Which makes it rather inconsistent. Especially if that string contains characters like a forward slash, a colon or semi-colon. Like when you have a URL as a value. I suppose it’s out of habit.

Thing is, it is not required. Strings can be quoted or not. There is no difference. It will still work with or without it. Even with spaces in that string. YAML allows it. Below are 2 examples:

phrase: 'The quick brown fox jumps over the lazy dog.'
poem: "Hey, diddle, diddle. The cat and the fiddle. The cow jumped over the moon."

The key part of the key-value pair can also be quoted too. The YAML won’t error out. Again, it’s allowed. So this is valid:

'foo':
  "bar": foobar

Single quote or double quotes don’t matter. It can be mixed. Above examples are both acceptable.

However, not quoting is not true in all cases. There are certain instances when it is required such as when there is a colon in the key. In this case, the key needs to be quoted.

'key:': value

What about quotes in the value itself?

CORRECT - phrase1: 'The quick ''brown'' fox jumped over the lazy dog.'
WRONG- phrase2: "The quick ""brown"" fox jumped over the lazy dog."
CORRECT - phrase3: "The quick \"brown\" fox jumped over the lazy dog."
WRONG - phrase4: "The quick '"brown"' fox jumped over the lazy dog."
CORRECT - phrase6: The quick 'brown' fox jumped over the lazy dog.
CORRECT - phrase7: The quick "brown" fox jumped over the lazy dog.

Finally, what does YAML mean?

It is short for – YAML Ain’t Markup Language.

How to render assets when building a static website with GitLab Pages and Jekyll

I’m using Jekyll to build a static site and deploy it with GitLab Pages. This site is compounded of posts (contained in the site/_posts folder) and refer to other HTML and Markdown documents that I placed in an assets folder at the project’s root, as recommended by Jekyll docs.

When I build the website in the pipeline it runs and deploys it successfully to GitLab Pages. However, if I am able to find my posts, the links towards the files allegedly contained in assets return a 404. When I browse the public artifacts file, I can’t see said files in the assets folder, even though I put them there before building the site.

What am I missing here? It runs fine when serving locally but as soon as it is deployed on GitLab Pages I can’t access the assets file.

project architecture:

site/
|__> _posts/
|____> entry.md
assets/
|__> v{{ version }}/
|____> yellow-ducky.html
|____> black-ducky.md

.gitlab-ci.yml excerpt:

pages:
  stage: deploy
  tags: [docker-connect]
  script:
    # entry.md is the blog post I want to publish
    - mv entry.md site/_posts/`date +'%Y-%m-%d'`-entry.md
    # reports come from a previous job's artifacts and contain all files I want to place in assets
    - mkdir -p assets assets/v${TAG}
    - mv reports/* assets/v${TAG}/
    # build website
    - gem install bundler
    - cd site
    - bundle install
    - bundle exec jekyll build -d public
    # move built files to the folder where GitLab expects to find them
    - cd .. && mkdir -p public && mv site/public/* public/
  artifacts:
    paths:
      - public

_config.yml excerpt:

title: RubberDucky
email: rubber@duck.io
description: >- # this means to ignore newlines until "baseurl:"
  This is the place where to find all info you need about rubber ducks. 
baseurl: "/toys/rubberduck" # the subpath of your site, e.g. /blog
url: "https://gitlab.troubleshoot.io" # the base hostname & protocol for your site, e.g. http://example.com
# Build settings
theme: minima
plugins:
  - jekyll-feed

blog post excerpt:

<ul style="list-style-type:none">
    {% for duck in ducks %}
        <h2>{{ duck.name }}</h2>
        <li><a href="assets/v{{ version }}/{{ duck.url }}">View</a> | <a href="assets/v{{ version }}/{{ duck.url }}" download>Download</a></li>
    {% endfor %}
</ul>

Go to Source
Author: avazula

Get key value from a go template in Prometheus/Alertmanager/Jiralert attempt to map severity to Jira task

I am using Prometheus Alertmanager integration with Jiralert go tool to create tasks out of alerts in Jira.
Everything works as expected aside from the fact that I don’t know how to inherit severity from the current alert. I am hard-coding a value at this point. I have tried to get the value from .Labels (which is get successfully during template, but not if I call it from config yaml.

# Content of jiralert.yaml
# Global defaults, applied to all receivers where not explicitly overridden. Optional.
defaults:
  # API access fields.
  api_url: https://test.atlassian.net
  user: 'as@test.com'
  password: 'randompassword'

  # The type of JIRA issue to create. Required.
  issue_type: Alert
  # Issue priority. Optional.
  #priority: Low
  # Go template invocation for generating the summary. Required.
  summary: '{{ template "jira.summary" . }}'
  # Go template invocation for generating the description. Optional.
  description: '{{ template "jira.description" . }}'
  # State to transition into when reopening a closed issue. Required.
  reopen_state: "To Do"
  # Do not reopen issues with this resolution. Optional.
  wont_fix_resolution: "Won't Fix"
  # Amount of time after being closed that an issue should be reopened, after which, a new issue is created.
  # Optional (default: always reopen)
  reopen_duration: 0h

# Receiver definitions. At least one must be defined.
receivers:
# Non-prod cluster for testing
  - name: 'prometheus-test-non-production'
    # JIRA project to create the issue in. Required.
    summary: '{{ template "jira.testenv.summary" . }}'
    description: '{{ template "jira.testenv.description" . }}'
    project: AS
    # Copy all Prometheus labels into separate JIRA labels. Optional (default: false).
    add_group_labels: false
    fields:
      customfield_10600: { "value": '{{ template ".Alerts.Front().Labels.severity.Value" }}' }
template: jiralert_v2.tmpl
# jiralert_v2.tmpl
{{ define "jira.summary" }}{{end}}
{{ define "jira.description" }}{{end}}

{{ define "jira.testenv.summary" }}[Prometheus][K8s/testenv-ops][{{ .Status | toUpper }}{{- if eq .Status "firing" -}}:{{- .Alerts.Firing | len -}}{{- end -}}]{{ .CommonLabels.alertname }} for {{ .CommonLabels.job }}{{- end }}{{- if gt (len .CommonLabels) (len .GroupLabels) -}}{{" "}}({{- with .CommonLabels.Remove .GroupLabels.Names }}{{- range $index, $label := .SortedPairs -}}{{ if $index }}, {{ end }}{{- $label.Name }}="{{ $label.Value -}}"{{- end }}{{- end -}}){{- end }}
{{ define "jira.testenv.description" }}
    {{ with index .Alerts 0 -}}
    *URL: <{{ .GeneratorURL }}>*
    {{- if .Annotations.runbook }} :notebook: *<{{ .Annotations.runbook }}|Runbook>*{{ end }}
    {{ end }}
    Kubernetes Cluster: testenv-ops
    Prometheus Alert Details:
    {{ range .Alerts}}
      * Alert Labels:
    {{ range .Labels.SortedPairs }}    ** {{ .Name }}: {{ .Value }}
    {{ end }}
      * Alert Description: {{ .Annotations.message }}
    {{ end }}
{{- end }}

Go to Source
Author: anVzdGFub3RoZXJodW1hbg

yaml files in jenkins pipeline

Just started out working on jenkins, among other things I’m trying to understand the role of yaml in pipelines. I understand that pipelines or declarative pipeline (do other type of pipelines exist in jenkins?) are defined using a syntax that is based on an extension of groovy and that yaml can be used along with some plugins or extended library to generate an on the fly groovy-based pipeline definition. Is my understanding correct?

Go to Source
Author: whatever