24
loading...
This website collects cookies to deliver better user experience
Variable Name | Description | Example |
---|---|---|
JOB_NAME | Provides the name of the job in Jenkins | envvars |
JOB_URL | Gives the URL to the job in the Jenkins UI | http://localhost:8082/job/envvars/ |
BUILD_NUMBER | Prints the build number in Jenkins console output | 5,6, etc. |
BUILD_TAG | Gives a unique tag for a specific job name and build number | envvars-build-8 |
${YOUR_JENKINS_HOST}/env-vars.html
. http://localhost:8080/
).pipeline{
agent any
stages{
stage("Env Variables"){
steps{
bat ‘set’
}
}
}
}
pipeline{
agent any
stages{
stage("Env Build Number"){
steps{
echo "The build number is ${env.BUILD_NUMBER}"
echo "You can also use \${BUILD_NUMBER} -> ${BUILD_NUMBER}"
}
}
}
}
import hudson.EnvVars;
import hudson.slaves.EnvironmentVariablesNodeProperty;
import hudson.slaves.NodeProperty;
import hudson.slaves.NodePropertyDescriptor;
import hudson.util.DescribableList;
import jenkins.model.Jenkins;
public createGlobalEnvironmentVariables(String key, String value){
Jenkins instance = Jenkins.getInstance();
DescribableList<NodeProperty<?>, NodePropertyDescriptor> globalNodeProperties = instance.getGlobalNodeProperties();
List<EnvironmentVariablesNodeProperty> envVarsNodePropertyList = globalNodeProperties.getAll(EnvironmentVariablesNodeProperty.class);
EnvironmentVariablesNodeProperty newEnvVarsNodeProperty = null;
EnvVars envVars = null;
if ( envVarsNodePropertyList == null || envVarsNodePropertyList.size() == 0 ) {
newEnvVarsNodeProperty = new hudson.slaves.EnvironmentVariablesNodeProperty();
globalNodeProperties.add(newEnvVarsNodeProperty);
envVars = newEnvVarsNodeProperty.getEnvVars();
} else {
envVars = envVarsNodePropertyList.get(0).getEnvVars();
}
envVars.put(key, value)
instance.save()
}
createGlobalEnvironmentVariables('Var1','Dummy')
Username = root
Access_Token = ***************
stage(“reading properties from properties file”) {
steps {
// Use a script block to do custom scripting
script {
def props = readProperties file: 'extravars.properties'
env.Username = props.Username
}
echo "The username is $Username"
}
}
environment {
DISABLE_AUTH = 'true'
}
pipeline {
agent any
environment {
DISABLE_AUTH = 'true' //can be used in whole pipeline
}
stages {
stage(“Build”) {
steps {
echo env.DISABLE_AUTH
}
}
}
}
pipeline {
agent any
environment {
DISABLE_AUTH = 'true'
}
stages {
stage(“Build”) {
environment {
ENABLE_AUTH = ‘false’ //can be used in this stage only
}
steps {
echo env.DISABLE_AUTH
echo env.ENABLE_AUTH
}
}
}
}
node{
stage('Build') {
withEnv(["DISABLE_AUTH=true"]) {
echo env.DISABLE_AUTH }
}
}
pipeline {
agent any
stages {
stage("capturing output in Environment Variables") {
steps {
script {
env.LS = bat(script:'dir', returnStdout: true).trim()
// if you access environment variable in the batch command
echo $LS
}
}
}
}
pipeline{
agent any
environment{
LT_USERNAME='[email protected]'
LT_ACCESS_KEY='iHnnmi0atXDjDKIqckdBH0gU72Uf8zJb76EyNlXjzvGPzvr54'
LT_TUNNEL=true
}
stages{
stage('printing the environment variables'){
steps{
echo env.LT_USERNAME
echo env.LT_ACCESS_KEY
echo env.LT_TUNNEL
}
}
}
}
http://localhost:8082/
and Login to the Jenkins Server.#!/usr/bin/env groovy
node {
// Sets the environment variables from LambdaTest for testing
withEnv(["[email protected]",
"LT_ACCESS_KEY=z71l7Q9ohS9HhKiCqd690mH0sDu5AYrz8VSB0whO3mZ2JEkNAN",
"LT_TUNNEL=true"]){
// Just printing the above set environment variables
echo env.LT_USERNAME
echo env.LT_ACCESS_KEY
stage('setup') {
// Get some code from a GitHub repository
try{
git 'https://github.com/LambdaTest/nightwatch-selenium-sample.git'
//Download Tunnel Binary
bat 'wget "https://downloads.lambdatest.com/tunnel/v3/windows/64bit/LT_Windows.zip"'
//Required if unzip is not installed
bat 'unzip -o LT_Windows.zip'
//Starting Tunnel Process
'LT --user ${LT_USERNAME} --key ${LT_ACCESS_KEY}'
}
catch (err){
echo err
}
}
stage('build') {
// Installing Dependencies
bat 'npm install'
bat 'npm install nightwatch'
}
stage('test') {
try{
// Running the nightwatch tests with environment set as Chrome
bat 'node_modules/.bin/nightwatch -e chrome tests'
}
catch (err){
echo err
}
}
stage('end') {
// Printing the success message
echo "Success"
}
}
}
https://accounts.lambdatest.com/login