I am trying to get the email id of the user who committed the changes into bitbucket from Jenkins. I have a user-defined variable named EMAIL_ID
which has the default value example1@gmail.com
. Using web-hook I trigger the Jenkins job. The Jenkins job has the following PowerShell script for finding the email id of the user who committed into bitbucket:
git log -n 1 > git.log
$var = Select-String -Path .\git.log -Pattern "@gmail.com"
$regex = "[a-zA-Z0-9_.-]+@gmail.com"
$email = [regex]::matches($var, $regex).value
$ENV:EMAIL_ID=$email
When I echo the $email
, I get example2@gmail.com
. But the scope of this variable is within this script only. Even if I assign $ENV:EMAIL_ID=$email
, its not working as expected. I need to access this variable from other build steps in the same job. In other words I need to make this variable as a global one, so I can access this from anywhere within the job. Is there any way to achieve this? Thanks in advance!!