diff --git a/x-pack/plugins/fleet/server/services/epm/agent/agent.test.ts b/x-pack/plugins/fleet/server/services/epm/agent/agent.test.ts index 0110df19175223..e3e422dda50094 100644 --- a/x-pack/plugins/fleet/server/services/epm/agent/agent.test.ts +++ b/x-pack/plugins/fleet/server/services/epm/agent/agent.test.ts @@ -22,12 +22,16 @@ password: {{password}} {{#if password}} hidden_password: {{password}} {{/if}} +{{#if optional_field}} +optional_field: {{optional_field}} +{{/if}} foo: {{bar}} some_text_field: {{should_be_text}} `; const vars = { paths: { value: ['/usr/local/var/log/nginx/access.log'] }, password: { type: 'password', value: '' }, + optional_field: { type: 'text', value: undefined }, bar: { type: 'text', value: 'bar' }, should_be_text: { type: 'text', value: '1234' }, }; diff --git a/x-pack/plugins/fleet/server/services/epm/agent/agent.ts b/x-pack/plugins/fleet/server/services/epm/agent/agent.ts index d279eb3088ab7d..5e1d823767fb57 100644 --- a/x-pack/plugins/fleet/server/services/epm/agent/agent.ts +++ b/x-pack/plugins/fleet/server/services/epm/agent/agent.ts @@ -87,7 +87,7 @@ function buildTemplateVariables(variables: PackagePolicyConfigRecord, templateSt } else if ( recordEntry.type && recordEntry.type === 'text' && - recordEntry.value.length && + recordEntry.value?.length && !isNaN(+recordEntry.value) ) { varPart[lastKeyPart] = `"${recordEntry.value}"`;