Run same script in multiple environments

I'd like to reuse the same script for different environments. The opening URL is dependent on passed in parameter.
For each Fleet agent policy, I'd like the passed in parameter to apply to just that script, but not shared with the others.

Would it be something like inserting under Advanced Browser Options --> Synthetics agent options --> Synthetics args the value "params: {activeEnv: 0}"

Here's an example:

Monitor Environment #1

const MY_MONITOR_ENV_0 = 0;
const MY_MONITOR_ENV_1 = 1;

**let activeEnv = MY_MONITOR_ENV_0;**
const myLocation = [
  "https://www.computerhope.com/jargon/o/operator.htm",
  "https://www.computerhope.com/jargon/h/hardware.htm",
];

step ('Enter site',async () => {
		await page.goto(myLocation[**activeEnv**] );
});

======================

Monitor Environment #2

const MY_MONITOR_ENV_0 = 0;
const MY_MONITOR_ENV_1 = 1;

**let activeEnv = MY_MONITOR_ENV_1;**
const myLocation = [
  "https://www.computerhope.com/jargon/o/operator.htm",
  "https://www.computerhope.com/jargon/h/hardware.htm",
];

step ('Enter site',async () => {
		await page.goto(myLocation[**activeEnv**] );
});

I also tried adding parameters via the UI.
On the command line, I tested and verified that I can pass in values
npx @elastic/synthetics --inline --params '{"loc": "DEV"}'

and use the passed in value

switch(params.loc) {
	case "DEV":
		console.log('Set Dev environment');
		activeEnv = DEV_MONITOR_ENV;
		break;
	case "QA":
		console.log('Set QA environment');
		activeEnv = QA_MONITOR_ENV;
		break;	
	default:
		console.log('<' + params.loc + '> is unknown environment');
		activeEnv = 99;	// Throw error 
	
}

However when I insert the JSON value into Synthetic parameters entry field, the properties are not read in my code.
For Source Type = Inline Script (not Zip URL)
Under Advanced Browser Options --> Synthetic agent options --> Synthetics args
I inserted JSON string {"loc": "QA"}

I received this error
image

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.