-
Notifications
You must be signed in to change notification settings - Fork 144
How to set environment variable in script? #5
Copy link
Copy link
Open
Description
Thanks for your videos and examples, they help me much in jenkins study.
I got trouble when I wanted to set environment variable in script.
I write a shell script gen_tag.sh, like this:
#!/bin/bash
if [[ "$GIT_BRANCH" =~ ^v ]]; then
export TAG="${GIT_BRANCH}"
else
export TAG="${GIT_COMMIT:0:12}"
fi
echo "$TAG"and in Jenkinsfile, this is a example:
pipeline {
agent any
stages {
stage('PreTest') {
steps {
catchError(buildResult:'UNSTABLE',stageResult:'UNSTABLE') {
sh 'chmod +x ./gen_tag.sh'
sh './gen_tag.sh'
}
echo currentBuild.result
}
}
stage('Prepare') {
steps {
catchError {
echo "$TAG" // it cause wrong, cannot get TAG from env
}
echo currentBuild.result
}
}
}
}
In fact, I cannot get TAG value from environment. Does there have some ideas to set environment variable in script?
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels