How to pass urlencoded string to jenkins api using ansible?

I have to pass value to jenkins api. But jenkins api accept value in urlencode. I tried to use filter urlencode in ansible, but it gives error.

- name: Add credential to add node
  uri:
      body: |
          json={
              "": "0",
              "credentials": {
                "scope": "GLOBAL",
                "id": "jenkins_linux_slave2_auth",
                "username": "jenkins",
                "password": "",
                "privateKeySource": {
                  "stapler-class": "com.cloudbees.jenkins.plugins.sshcredentials.impl.BasicSSHUserPrivateKey$DirectEntryPrivateKeySource",
                  "privateKey": '{{"URL ENCODED STRING"|urlencode}}'
                },
                "description": "Jenkins Linux Slave2 Authentication",
                "stapler-class": "com.cloudbees.jenkins.plugins.sshcredentials.impl.BasicSSHUserPrivateKey"
              }
            }
      force_basic_auth: yes
      method: POST
      password: "{{ jenkins_user_token }}"
      status_code: 302
      url: "{{ jenkins_url }}/credentials/store/system/domain/_/createCredentials"
      user: "{{ jenkins_user }}"
      validate_certs: no
  tags:
      - credential

This play gives error

TASK [jenkins_config : Add credential to add node] ************************************************************************************************************************************************************************************
task path: /home/nile2691/ansible_playbooks/roles/jenkins_config/tasks/main.yaml:34
fatal: [localhost]: FAILED! => {
    "msg": "template error while templating string: no filter named 'urlencode'. String: json={\n    \"\": \"0\",\n    \"credentials\": {\n      \"scope\": \"GLOBAL\",\n      \"id\": \"jenkins_linux_slave2_auth\",\n      \"username\": \"jenkins\",\n      \"password\": \"\",\n      \"privateKeySource\": {\n        \"stapler-class\": \"com.cloudbees.jenkins.plugins.sshcredentials.impl.BasicSSHUserPrivateKey$DirectEntryPrivateKeySource\",\n        \"privateKey\": '{{\"URL ENCODED STRING\"|urlencode}}'\n      },\n      \"description\": \"Jenkins Linux Slave2 Authentication\",\n      \"stapler-class\": \"com.cloudbees.jenkins.plugins.sshcredentials.impl.BasicSSHUserPrivateKey\"\n    }\n  }\n"
}

Is there another way to pass value in urlencode in jenkins ?

0
задан 8 February 2018 в 19:08
1 ответ

Появляется сообщение об ошибке:

нет фильтра с именем 'urlencode'

Если вы посмотрите здесь , вы заметите, что он поддерживается в Jinja2 версии 2.7+ .
Обновите свой пакет Jinja2.

1
ответ дан 4 December 2019 в 16:02

Теги

Похожие вопросы