How to access UID
variable in Jenkins pipeline job?
I got null
when do:
pipeline {
agent any
environment {
def userId = "${env.UID}";
}
stages {
stage('Print UID') {
steps {
script {
echo "${userId}"
}
}
}
}
}
Jenkins is hosted on Ubuntu 16.04
This code creates a local variable in the scope of the environment
block.
From the documentation the environment
dir uses "setter" style properties. You can change your code to:
environment {
userId = "${env.UID}";
}
This will make the environment variable userId
available in the other parts of the pipeline (could be proven by performing a sh 'env'
or something similar).
But, before that, I am not sure where "${env.UID}"
comes from. If it is a plugin you have, then it will work great. If not, then you will have to figure out how to get the value you are expecting.
you can use this code.
environment {
userId = sh(script: "id -u ${USER}", returnStdout: true)
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With