Helmfile: How to convert a ![]map into String

Created on 13 Apr 2020  路  4Comments  路  Source: roboll/helmfile

Hello, I have a little issue on running Jenkins with Helmfile.
I want to use Helmfile passing arguments with my Job configuration.

Using a Helm Values file it would be:

master:
  jobs:
    test-job: |-
      <?xml version='1.0' encoding='UTF-8'?>
      <project>
        <keepDependencies>false</keepDependencies>
        <properties/>
        <scm class="hudson.scm.NullSCM"/>
        <canRoam>false</canRoam>
        <disabled>false</disabled>
        <blockBuildWhenDownstreamBuilding>false</blockBuildWhenDownstreamBuilding>
        <blockBuildWhenUpstreamBuilding>false</blockBuildWhenUpstreamBuilding>
        <triggers/>
        <concurrentBuild>false</concurrentBuild>
        <builders/>
        <publishers/>
        <buildWrappers/>
      </project>
    test-job-2: |-
      <?xml version='1.0' encoding='UTF-8'?>
      <project>
        <keepDependencies>false</keepDependencies>
        <properties/>
        <scm class="hudson.scm.NullSCM"/>
        <canRoam>false</canRoam>
        <disabled>false</disabled>
        <blockBuildWhenDownstreamBuilding>false</blockBuildWhenDownstreamBuilding>
        <blockBuildWhenUpstreamBuilding>false</blockBuildWhenUpstreamBuilding>
        <triggers/>
        <concurrentBuild>false</concurrentBuild>
        <builders/>
        <publishers/>
        <buildWrappers/>

How could this be achieved using Helmfile?

I'm running in version v0.106.3.

question

Most helpful comment

This is exactly what I was looking for! You're awesome! Thanks!

All 4 comments

@mschirbel I think I don't undestand your question fully, but anyways...

You could just write a helmfile.yaml like this:

releases:
- name: yourchart
  chart: yourcharts/jenkins
  values:
  - values.yaml

values.yaml referenced from within the helmfile.yaml above would contain the exact content of your Job configuration.

Does this make sense? Otherwise, an example helm command that you would use to install the job configuration with helm would help me translating it to a helmfile config.

Hell @mumoshu , I think I understood what you said, and yes, it would be easiar. I'm just trying to understand how I can use the set module:

releases:
- name: "jenkins"
  namespace: "jenkins"
  labels:
    chart: "jenkins"
    repo: "stable"
  chart: "stable/jenkins"
  wait: true
  set:
    - name: master.slaveListenerServiceType
      value: "NodePort"
    - name: master.master.serviceType
      value: "NodePort"

In order to use that I must call the attributes referenced here.

And under the master.jobs attribute we have:

master.jobs | Jenkins XML job configs | {}

How can I use this inside the the helmfile configuration? I'm confused with the {} notation. It does not seem to work with helmfile.

@mschirbel Ah okay!

Even in that case I would generally recommend values over sets.

values accepts inline objects so you could just write:

releases:
- name: "jenkins"
  namespace: "jenkins"
  labels:
    chart: "jenkins"
    repo: "stable"
  chart: "stable/jenkins"
  wait: true
  values:
  - master:
      slaveListenerServiceType: NodePort
      serviceType: NodePort
      jobs:
      test-job: |-
        <?xml version='1.0' encoding='UTF-8'?>
        <project>
          <keepDependencies>false</keepDependencies>
          <properties/>
          <scm class="hudson.scm.NullSCM"/>
          <canRoam>false</canRoam>
          <disabled>false</disabled>
          <blockBuildWhenDownstreamBuilding>false</blockBuildWhenDownstreamBuilding>
          <blockBuildWhenUpstreamBuilding>false</blockBuildWhenUpstreamBuilding>
          <triggers/>
          <concurrentBuild>false</concurrentBuild>
          <builders/>
          <publishers/>
          <buildWrappers/>
        </project>
      test-job-2: |-
        <?xml version='1.0' encoding='UTF-8'?>
        <project>
          <keepDependencies>false</keepDependencies>
          <properties/>
          <scm class="hudson.scm.NullSCM"/>
          <canRoam>false</canRoam>
          <disabled>false</disabled>
          <blockBuildWhenDownstreamBuilding>false</blockBuildWhenDownstreamBuilding>
          <blockBuildWhenUpstreamBuilding>false</blockBuildWhenUpstreamBuilding>
          <triggers/>
          <concurrentBuild>false</concurrentBuild>
          <builders/>
          <publishers/>
          <buildWrappers/>

If you still need set, it "could" be:

  set:
    - name: master.slaveListenerServiceType
      value: "NodePort"
    - name: master.serviceType
      value: "NodePort"
    - name: master.jobs.test-job
      value: |
        <?xml version='1.0' encoding='UTF-8'?>
        <project>
          <keepDependencies>false</keepDependencies>
          <properties/>
          <scm class="hudson.scm.NullSCM"/>
          <canRoam>false</canRoam>
          <disabled>false</disabled>
          <blockBuildWhenDownstreamBuilding>false</blockBuildWhenDownstreamBuilding>
          <blockBuildWhenUpstreamBuilding>false</blockBuildWhenUpstreamBuilding>
          <triggers/>
          <concurrentBuild>false</concurrentBuild>
          <builders/>
          <publishers/>
          <buildWrappers/>
        </project>

// But honestly saying, I have never tried set with such a large value. It's directly translated to helm upgrade --set master.jobs.test-job=<LARGE CONFIG> which subject to (I believe) your os/shell limit of max command line length.

Have you heard of helm upgrade --set-file foo.bar=FILEPATH syntax?

Helmfile also support that. That's much better than set:

  set:
    - name: master.slaveListenerServiceType
      value: "NodePort"
    - name: master.serviceType
      value: "NodePort"
    - name: master.jobs.test-job
      file: test-job.xml

This is exactly what I was looking for! You're awesome! Thanks!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ivandardi picture ivandardi  路  3Comments

madAndroid picture madAndroid  路  3Comments

mumoshu picture mumoshu  路  4Comments

michaelpporter picture michaelpporter  路  3Comments

marianogg9 picture marianogg9  路  3Comments