I am trying to access the variable set in one task from another task in JavaScript.
In the first task I am setting the variable as following:
var connection = tl.getInput("connection", true);
if(connection !== undefined) {
var auth = tl.getEndpointAuthorization(connection, false);
let access_key_1 = auth.parameters["password"];
let username = auth.parameters["username"];
if(auth !== undefined) {
console.log('##vso[task.setvariable variable=access_key_1;]', access_key_1);
}
In the second task i am trying to access the variable:
console.log(access_key_1);
But I am getting error:
ReferenceError: access_key_1 is not defined.
The variable you created it's an environment variable, not JS variable.
So, to access it you should use process.env.access_key_1. if you to print:
console.log(process.env.access_key_1)