---
- job:
    name: integration-puppet-deploy
    display-name: integration-puppet-deploy
    project-type: freestyle
    description: "Kicks off a Puppet deploy in the integration environment"
    builders:
      - shell: |
          JSON="{\"parameter\": [{\"name\": \"TAG\", \"value\": \"$TAG\"}], \"\": \"\"}"

          curl -f -XPOST https://<%= @jenkins_integration_api_user %>:<%= @jenkins_integration_api_password %>@deploy.integration.publishing.service.gov.uk/job/Deploy_Puppet/build -d token=<%= @puppet_auth_token %> --data-urlencode json="$JSON"
    wrappers:
        - ansicolor:
            colormap: xterm
    parameters:
        - string:
            name: TAG
            description: 'Git tag/committish to deploy.'
            default: 'release'
    publishers:
        - description-setter:
            regexp: ""
            description: "$TAG"

---
- job:
    name: integration-puppet-deploy
    display-name: integration-puppet-deploy
    project-type: freestyle
    description: "Kicks off a Puppet deploy in the integration environment"
    builders:
      - shell: |
          JSON="{\"parameter\": [{\"name\": \"TAG\", \"value\": \"$TAG\"}], \"\": \"\"}"

          CRUMB=$(curl https://<%= @jenkins_integration_api_user %>:<%= @jenkins_integration_api_password %>@deploy.integration.publishing.service.gov.uk/crumbIssuer/api/json | jq '. | .crumb' | sed 's/"//g"')

          curl -f -H "Jenkins-Crumb:$CRUMB" -XPOST https://<%= @jenkins_integration_api_user %>:<%= @jenkins_integration_api_password %>@deploy.integration.publishing.service.gov.uk/job/Deploy_Puppet/build -d token=<%= @puppet_auth_token %> --data-urlencode json="$JSON"
    wrappers:
        - ansicolor:
            colormap: xterm
    parameters:
        - string:
            name: TAG
            description: 'Git tag/committish to deploy.'
            default: 'release'
    publishers:
        - description-setter:
            regexp: ""
            description: "$TAG"

Add Crumb Issuer to Puppet job
Add Crumb Issuer to Puppet job
