How to replace backslash in jsonnet?

#1

First of all I want to thank you for the work of developing this tool.
Well, I’ll tell you the problem. I’m using jsonnet files and when I try to use substitutions I can’t escape the “/” character.

Example 1:

local BuildContainer() = {
  kind: "pipeline",
  name: "build_ci_docker",
  steps: [
    {
      name: "docker_tags",
      image: "debian:stable-slim",
      commands: [
        |||
          echo -n "${DRONE_COMMIT_SHA},${DRONE_COMMIT_BRANCH/\//__},ci-${DRONE_BUILD_NUMBER}" > .tags
        |||,
      ],
      // Must generate: /\//__
    },
    {
      name: "build_docker",
      image: "plugins/gcr",
      settings: {
        dry_run: true,
        repo: "eu.gcr.io/project_name/image_name/",
        registry: "eu.gcr.io",
        ignore_missing: true,
        cache_from: [
          "eu.gcr.io/project_name/image_name/" + ":${DRONE_COMMIT_BRANCH/\//__}",
        ],
      },
    },
  ]
};

[
  BuildContainer(),
]

Result 1:

kind: pipeline
name: build_ci_docker

platform:
  os: linux
  arch: amd64

steps:
- name: docker_tags
  image: debian:stable-slim
  commands:
  - "echo -n \"${DRONE_COMMIT_SHA},${DRONE_COMMIT_BRANCH/\\//__},ci-${DRONE_BUILD_NUMBER}\" > .tags\n"

- name: build_docker
  image: plugins/gcr
  settings:
    cache_from:
    - "eu.gcr.io/project_name/image_name/:${DRONE_COMMIT_BRANCH///__}"
    dry_run: true
    ignore_missing: true
    registry: eu.gcr.io
    repo: eu.gcr.io/project_name/image_name/
...

Example 2:

local BuildContainer() = {
  kind: "pipeline",
  name: "build_ci_docker",
  steps: [
    {
      name: "docker_tags",
      image: "debian:stable-slim",
      commands: [
        |||
          echo -n "${DRONE_COMMIT_SHA},${DRONE_COMMIT_BRANCH/\\//__},ci-${DRONE_BUILD_NUMBER}" > .tags
        |||,
      ],
      // Must generate: /\//__
    },
    {
      name: "build_docker",
      image: "plugins/gcr",
      settings: {
        dry_run: true,
        repo: "eu.gcr.io/project_name/image_name/",
        registry: "eu.gcr.io",
        ignore_missing: true,
        cache_from: [
          "eu.gcr.io/project_name/image_name/" + ":${DRONE_COMMIT_BRANCH/\\//__}",
        ],
      },
    },
  ]
};

[
  BuildContainer(),
]

Result 2:

kind: pipeline
name: build_ci_docker

platform:
  os: linux
  arch: amd64

steps:
- name: docker_tags
  image: debian:stable-slim
  commands:
  - "echo -n \"${DRONE_COMMIT_SHA},${DRONE_COMMIT_BRANCH/\\\\//__},ci-${DRONE_BUILD_NUMBER}\" > .tags\n"

- name: build_docker
  image: plugins/gcr
  settings:
    cache_from:
    - "eu.gcr.io/project_name/image_name/:${DRONE_COMMIT_BRANCH/\\//__}"
    dry_run: true
    ignore_missing: true
    registry: eu.gcr.io
    repo: eu.gcr.io/project_name/image_name/
...

In neither of the two cases of each example the substitution of the character “/” in the name of the branch is accomplished. Any idea?.

Thank you very much

0 Likes