Jenkins if statmentif else bash scriptHow do I set an environment variable for sudo in MacOS?jenkins hook up...
How can I shoot a bow using Strength instead of Dexterity?
Does an Irish VISA WARNING count as "refused entry at the border of any country other than the UK?"
Can the average speed of a moving body be 0?
Do I need to start off my book by describing the character's "normal world"?
A man in the desert is bitten by a skeletal animal, its skull gets stuck on his arm
To show that a recursively defined sequence is Cauchy - How?
Is Thieves' Cant a language?
Why does the cable resistance jump from a low value to high value at a particular frequency?
Suspension compromise for urban use
Doesn't the speed of light limit imply the same electron can be annihilated twice?
Sum Square Difference, which way is more Pythonic?
Is it really Security Misconfiguration to show a version number?
How would you translate this? バタコチーズライス
A+ rating still unsecure by Google Chrome's opinion
Why does this Jet Provost strikemaster have a textured leading edge?
Unconventional examples of mathematical modelling
How can I find files in directories listed in a file?
Word for an event that will likely never happen again
When was "Fredo" an insult to Italian-Americans?
Should I leave building the database for the end?
Telephone number in spoken words
Installing Windows to flash UEFI/ BIOS, then reinstalling Ubuntu
What is a "soap"?
Running code generated in realtime in JavaScript with eval()
Jenkins if statment
if else bash scriptHow do I set an environment variable for sudo in MacOS?jenkins hook up with apache sites-enabledJenkins, Python and rootHow to launch jenkins?Running a script through jenkinsunable to load variable value in jenkins buildJenkins write permission on linuxJenkins on solaris operating systemPrevent Script from Inserting Space in File Nameunable to access env.$variable in jenkins pipeline with groovy
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ margin-bottom:0;
}
I am trying to write a simple If statement on the Execute Shell of Jenkins (1.638).
I looked on similar issue and it still didn't work (see below the result output).
I tried both [[ and [ and relevant spaces, It appears that Jenkins handles if differently than on regular bash. I even tried the then on the same line as the if with ;. Any idea ?
if [[ "${BRANCH_NAME}" == "master" ]] || [[ "${BRANCH_NAME}" == "master_dev" ]]
then
./runUnitTests.sh ${REPOSITORY_NAME} ${BASE_BUILD_CORE} ${BRANCH_NAME} ${BUILD_NUMBER} || echo "The npm may fail but the report exists"
fi
The result on Jenkins is
- [[ upgrade == master ]]
/tmp/hudson11669113852432623.sh: 2: /tmp/hudson11669113852432623.sh: [[: not found - [[ upgrade == master_dev ]]
/tmp/hudson11669113852432623.sh: 2: /tmp/hudson11669113852432623.sh: [[: not found
[core] $ /bin/sh -xe /tmp/hudson7252947297480815560.sh
bash jenkins
add a comment |
I am trying to write a simple If statement on the Execute Shell of Jenkins (1.638).
I looked on similar issue and it still didn't work (see below the result output).
I tried both [[ and [ and relevant spaces, It appears that Jenkins handles if differently than on regular bash. I even tried the then on the same line as the if with ;. Any idea ?
if [[ "${BRANCH_NAME}" == "master" ]] || [[ "${BRANCH_NAME}" == "master_dev" ]]
then
./runUnitTests.sh ${REPOSITORY_NAME} ${BASE_BUILD_CORE} ${BRANCH_NAME} ${BUILD_NUMBER} || echo "The npm may fail but the report exists"
fi
The result on Jenkins is
- [[ upgrade == master ]]
/tmp/hudson11669113852432623.sh: 2: /tmp/hudson11669113852432623.sh: [[: not found - [[ upgrade == master_dev ]]
/tmp/hudson11669113852432623.sh: 2: /tmp/hudson11669113852432623.sh: [[: not found
[core] $ /bin/sh -xe /tmp/hudson7252947297480815560.sh
bash jenkins
What does "didn't work" mean? Errors? Doesn't run?
– jasonwryan
Mar 24 '16 at 6:41
add a comment |
I am trying to write a simple If statement on the Execute Shell of Jenkins (1.638).
I looked on similar issue and it still didn't work (see below the result output).
I tried both [[ and [ and relevant spaces, It appears that Jenkins handles if differently than on regular bash. I even tried the then on the same line as the if with ;. Any idea ?
if [[ "${BRANCH_NAME}" == "master" ]] || [[ "${BRANCH_NAME}" == "master_dev" ]]
then
./runUnitTests.sh ${REPOSITORY_NAME} ${BASE_BUILD_CORE} ${BRANCH_NAME} ${BUILD_NUMBER} || echo "The npm may fail but the report exists"
fi
The result on Jenkins is
- [[ upgrade == master ]]
/tmp/hudson11669113852432623.sh: 2: /tmp/hudson11669113852432623.sh: [[: not found - [[ upgrade == master_dev ]]
/tmp/hudson11669113852432623.sh: 2: /tmp/hudson11669113852432623.sh: [[: not found
[core] $ /bin/sh -xe /tmp/hudson7252947297480815560.sh
bash jenkins
I am trying to write a simple If statement on the Execute Shell of Jenkins (1.638).
I looked on similar issue and it still didn't work (see below the result output).
I tried both [[ and [ and relevant spaces, It appears that Jenkins handles if differently than on regular bash. I even tried the then on the same line as the if with ;. Any idea ?
if [[ "${BRANCH_NAME}" == "master" ]] || [[ "${BRANCH_NAME}" == "master_dev" ]]
then
./runUnitTests.sh ${REPOSITORY_NAME} ${BASE_BUILD_CORE} ${BRANCH_NAME} ${BUILD_NUMBER} || echo "The npm may fail but the report exists"
fi
The result on Jenkins is
- [[ upgrade == master ]]
/tmp/hudson11669113852432623.sh: 2: /tmp/hudson11669113852432623.sh: [[: not found - [[ upgrade == master_dev ]]
/tmp/hudson11669113852432623.sh: 2: /tmp/hudson11669113852432623.sh: [[: not found
[core] $ /bin/sh -xe /tmp/hudson7252947297480815560.sh
bash jenkins
bash jenkins
edited Apr 13 '17 at 12:36
Community♦
1
1
asked Mar 24 '16 at 6:25
ChenChen
231 gold badge1 silver badge5 bronze badges
231 gold badge1 silver badge5 bronze badges
What does "didn't work" mean? Errors? Doesn't run?
– jasonwryan
Mar 24 '16 at 6:41
add a comment |
What does "didn't work" mean? Errors? Doesn't run?
– jasonwryan
Mar 24 '16 at 6:41
What does "didn't work" mean? Errors? Doesn't run?
– jasonwryan
Mar 24 '16 at 6:41
What does "didn't work" mean? Errors? Doesn't run?
– jasonwryan
Mar 24 '16 at 6:41
add a comment |
1 Answer
1
active
oldest
votes
Have you considered including a bash shebang in your shell?
#!/bin/bash -xe
if [[ "${BRANCH_NAME}" == "master" ]] || [[ "${BRANCH_NAME}" == "master_dev" ]]
....
That will force Jenkins to use your local bash interpreter.
1
Great solution. The only problem is that when I use the shebang, It route the output to a different place and so you can't see if what happened. Jenkins behavior is a Debug mode. So to over come this I had add -x to the shebang. like this : #!/bin/bash -x
– Chen
Mar 24 '16 at 6:59
@Chen You can also just use the compatible[instead of thebash-specific[[:[ "${BRANCH_NAME}" = "master" ]
– Martin Tournoij
Mar 24 '16 at 7:28
Yes, as you found you'll need to use -x to get the output echoed to your Jenkins log. I find a lot of folks use -xe to get the output and exit on error as well.
– Michael J
Mar 29 '16 at 3:08
Thanks, I was going crazy with this. Just forgot to add the bash shebang
– nmat
Dec 16 '16 at 1:36
add a comment |
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "106"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f271877%2fjenkins-if-statment%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Have you considered including a bash shebang in your shell?
#!/bin/bash -xe
if [[ "${BRANCH_NAME}" == "master" ]] || [[ "${BRANCH_NAME}" == "master_dev" ]]
....
That will force Jenkins to use your local bash interpreter.
1
Great solution. The only problem is that when I use the shebang, It route the output to a different place and so you can't see if what happened. Jenkins behavior is a Debug mode. So to over come this I had add -x to the shebang. like this : #!/bin/bash -x
– Chen
Mar 24 '16 at 6:59
@Chen You can also just use the compatible[instead of thebash-specific[[:[ "${BRANCH_NAME}" = "master" ]
– Martin Tournoij
Mar 24 '16 at 7:28
Yes, as you found you'll need to use -x to get the output echoed to your Jenkins log. I find a lot of folks use -xe to get the output and exit on error as well.
– Michael J
Mar 29 '16 at 3:08
Thanks, I was going crazy with this. Just forgot to add the bash shebang
– nmat
Dec 16 '16 at 1:36
add a comment |
Have you considered including a bash shebang in your shell?
#!/bin/bash -xe
if [[ "${BRANCH_NAME}" == "master" ]] || [[ "${BRANCH_NAME}" == "master_dev" ]]
....
That will force Jenkins to use your local bash interpreter.
1
Great solution. The only problem is that when I use the shebang, It route the output to a different place and so you can't see if what happened. Jenkins behavior is a Debug mode. So to over come this I had add -x to the shebang. like this : #!/bin/bash -x
– Chen
Mar 24 '16 at 6:59
@Chen You can also just use the compatible[instead of thebash-specific[[:[ "${BRANCH_NAME}" = "master" ]
– Martin Tournoij
Mar 24 '16 at 7:28
Yes, as you found you'll need to use -x to get the output echoed to your Jenkins log. I find a lot of folks use -xe to get the output and exit on error as well.
– Michael J
Mar 29 '16 at 3:08
Thanks, I was going crazy with this. Just forgot to add the bash shebang
– nmat
Dec 16 '16 at 1:36
add a comment |
Have you considered including a bash shebang in your shell?
#!/bin/bash -xe
if [[ "${BRANCH_NAME}" == "master" ]] || [[ "${BRANCH_NAME}" == "master_dev" ]]
....
That will force Jenkins to use your local bash interpreter.
Have you considered including a bash shebang in your shell?
#!/bin/bash -xe
if [[ "${BRANCH_NAME}" == "master" ]] || [[ "${BRANCH_NAME}" == "master_dev" ]]
....
That will force Jenkins to use your local bash interpreter.
edited yesterday
answered Mar 24 '16 at 6:47
Michael JMichael J
3812 silver badges7 bronze badges
3812 silver badges7 bronze badges
1
Great solution. The only problem is that when I use the shebang, It route the output to a different place and so you can't see if what happened. Jenkins behavior is a Debug mode. So to over come this I had add -x to the shebang. like this : #!/bin/bash -x
– Chen
Mar 24 '16 at 6:59
@Chen You can also just use the compatible[instead of thebash-specific[[:[ "${BRANCH_NAME}" = "master" ]
– Martin Tournoij
Mar 24 '16 at 7:28
Yes, as you found you'll need to use -x to get the output echoed to your Jenkins log. I find a lot of folks use -xe to get the output and exit on error as well.
– Michael J
Mar 29 '16 at 3:08
Thanks, I was going crazy with this. Just forgot to add the bash shebang
– nmat
Dec 16 '16 at 1:36
add a comment |
1
Great solution. The only problem is that when I use the shebang, It route the output to a different place and so you can't see if what happened. Jenkins behavior is a Debug mode. So to over come this I had add -x to the shebang. like this : #!/bin/bash -x
– Chen
Mar 24 '16 at 6:59
@Chen You can also just use the compatible[instead of thebash-specific[[:[ "${BRANCH_NAME}" = "master" ]
– Martin Tournoij
Mar 24 '16 at 7:28
Yes, as you found you'll need to use -x to get the output echoed to your Jenkins log. I find a lot of folks use -xe to get the output and exit on error as well.
– Michael J
Mar 29 '16 at 3:08
Thanks, I was going crazy with this. Just forgot to add the bash shebang
– nmat
Dec 16 '16 at 1:36
1
1
Great solution. The only problem is that when I use the shebang, It route the output to a different place and so you can't see if what happened. Jenkins behavior is a Debug mode. So to over come this I had add -x to the shebang. like this : #!/bin/bash -x
– Chen
Mar 24 '16 at 6:59
Great solution. The only problem is that when I use the shebang, It route the output to a different place and so you can't see if what happened. Jenkins behavior is a Debug mode. So to over come this I had add -x to the shebang. like this : #!/bin/bash -x
– Chen
Mar 24 '16 at 6:59
@Chen You can also just use the compatible
[ instead of the bash-specific [[: [ "${BRANCH_NAME}" = "master" ]– Martin Tournoij
Mar 24 '16 at 7:28
@Chen You can also just use the compatible
[ instead of the bash-specific [[: [ "${BRANCH_NAME}" = "master" ]– Martin Tournoij
Mar 24 '16 at 7:28
Yes, as you found you'll need to use -x to get the output echoed to your Jenkins log. I find a lot of folks use -xe to get the output and exit on error as well.
– Michael J
Mar 29 '16 at 3:08
Yes, as you found you'll need to use -x to get the output echoed to your Jenkins log. I find a lot of folks use -xe to get the output and exit on error as well.
– Michael J
Mar 29 '16 at 3:08
Thanks, I was going crazy with this. Just forgot to add the bash shebang
– nmat
Dec 16 '16 at 1:36
Thanks, I was going crazy with this. Just forgot to add the bash shebang
– nmat
Dec 16 '16 at 1:36
add a comment |
Thanks for contributing an answer to Unix & Linux Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f271877%2fjenkins-if-statment%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
What does "didn't work" mean? Errors? Doesn't run?
– jasonwryan
Mar 24 '16 at 6:41