- ECK version: 8.14.0
- FLEET version: 8.14.0
- Synthetics Monitor agent version: 8.14.1
- @elastic/synthetics CLI version: 1.12.1
- Arch: on premise Kubernetes
Hello everyone!
I currently have a synthetic monitor running with CLI. The stages are working fine for me:
- Create project
- Develop the monitor (in .js and .ts)
- Publish in Kibana
I wanted to set security criteria using a .env file to keep sensitive information
------
.env
-----
PRIVATE_LOCATIONS=oke-svc-prod
SCHEDULE=5
GOTO=https://www.elastic.co/es/import dotenv from 'dotenv';
------
elastic-env.journey.js
-----
import dotenv from 'dotenv';
dotenv.config({path: path.resolve(__dirname, './.env') });
and I encountered two scenarios:
Scenario 1:
Inside monitor.user, I can reference the .env file, and the variables load correctly. I validated this by publishing the changes to Kibana, and the variables loaded fine. The variables I used were PRIVATE_LOCATIONS and SCHEDULE.
However, when I tried to use the GOTO variable in page.goto(process.env.GOTO)
, it failed. Sometimes it loads as empty, and other times it literally takes 'process.env.GOTO' as the value.
monitor.use({
id: 'elastic-env',
name : 'elastic-env',
tags : [ 'DOC-DEVOPS' ],
privateLocations: [process.env.PRIVATE_LOCATIONS],
schedule: parseInt(process.env.SCHEDULE), // Convertir a número
screenshot: 'on',
enabled: true
});
step('Go to https://www.elastic.co/es/', async () => {
const gotoPage = process.env.GOTO;
console.log('pageGoto: ', gotoPage);
await page.goto(gotoPage);
});
Scenario 2:
Due to the error when using GOTO in Scenario 1, I updated my synthetic agent deployment by loading the GOTO environment variable into the pod (I'm using K8s). With this change, the monitor worked.
elastic-agent@syntetics-agent-test-b95d84546-f7nqg:~$ env | grep GOTO
GOTO=https://www.elastic.co/es/
elastic-agent@syntetics-agent-test-b95d84546-f7nqg:~$
My question is:
Is there a way to use an environment variable from a .env file that can be recognized and used when running npx @elastic/synthetics push
?