I have an Azure Custom task in which I want to read secrets from a key vault. In order to authenticate against the KV, I have added a service connection in the pipeline's project. I know that name of the service connection in advanced and I want to use it directly without adding a new input to the custom task.
What I tried is this code:
const spId = tl.getEndpointAuthorizationParameter(serviceConnectionName, "serviceprincipalid", false);
const spKey = tl.getEndpointAuthorizationParameter(serviceConnectionName, "serviceprincipalkey", true);
const tenantId = tl.getEndpointAuthorizationParameter(serviceConnectionName, "tenantid", false);
if (!spId || !spKey || !tenantId)
{
throw new Error(`Could not retrieve SC info of: ${serviceConnectionName}`);
}
const credential = new ClientSecretCredential(tenantId, spId, spKey);
// Connect to KV
const client = new SecretClient(kvUrl, credential);
const secret = await client.getSecret("my-secret");
const secretval = secret.value;
and in task.json I added a definition of the endpoint like this:
"endpoint": [
{
"name": "kv-sbx-sc",
"type": "azurerm"
}
]
when running the custom task in the pipeline I get this error:
Endpoint auth data not present: kv-sbx-sc
How can I fix it?