shell scripting for jenkins
My Jenkins environment variable $SVN_URL
is http://project/svn/neslrepo/trunk/java_project
. I want to extract java_project
and store in a variable through my shell script.
I tried:
job_name=(echo $SVN_URL | awk -F "/" '{print $NF}')
echo $job_name.war
I expected the output to be java_project.war
, but it didn't work. What am I doing wrong?
shell-script shell
add a comment |
My Jenkins environment variable $SVN_URL
is http://project/svn/neslrepo/trunk/java_project
. I want to extract java_project
and store in a variable through my shell script.
I tried:
job_name=(echo $SVN_URL | awk -F "/" '{print $NF}')
echo $job_name.war
I expected the output to be java_project.war
, but it didn't work. What am I doing wrong?
shell-script shell
add a comment |
My Jenkins environment variable $SVN_URL
is http://project/svn/neslrepo/trunk/java_project
. I want to extract java_project
and store in a variable through my shell script.
I tried:
job_name=(echo $SVN_URL | awk -F "/" '{print $NF}')
echo $job_name.war
I expected the output to be java_project.war
, but it didn't work. What am I doing wrong?
shell-script shell
My Jenkins environment variable $SVN_URL
is http://project/svn/neslrepo/trunk/java_project
. I want to extract java_project
and store in a variable through my shell script.
I tried:
job_name=(echo $SVN_URL | awk -F "/" '{print $NF}')
echo $job_name.war
I expected the output to be java_project.war
, but it didn't work. What am I doing wrong?
shell-script shell
shell-script shell
edited Nov 30 at 10:47
terdon♦
128k31248423
128k31248423
asked Nov 30 at 9:35
user323573
111
111
add a comment |
add a comment |
4 Answers
4
active
oldest
votes
The shell already provides some nice tools to do this, no need for an external command:
$ SVN_URL="http://project/svn/neslrepo/trunk/java_project"
$ echo ${SVN_URL##*/}
java_project
So all you need is:
job_name=${SVN_URL##*/}.war
add a comment |
It appears that basename
can also do this, despite the argument being an HTTP URL instead of a filesystem path.
echo $(basename "http://project/svn/neslrepo/trunk/java_project/").war
java_project.war
Since the man page does not mention HTTP URLs, this is probably an abuse of basename
. It seems to be a side effect of the structural similarity between an HTTP URL and a filesystem path. man 3 basename
says (emphasis mine):
The functions dirname() and basename() break a null-terminated
pathname string into directory and filename components. In the usual
case, dirname() returns the string up to, but not including, the final
'/', and basename() returns the component following the final '/'.
Trailing '/' characters are not counted as part of the pathname.
add a comment |
I tried by below 2 methods and it worked fine
Method1
@praveen_linux_example ~]# SVN_URL=http://project/svn/neslrepo/trunk/java_project
[root@praveen_linux_example ~]# jobname=`echo $SVN_URL| awk -F "/" '{print $NF}'`
[root@praveen_linux_example ~]# echo $jobname.war
java_project.war
======================================================================================================
Method 2
SVN_URL=http://project/svn/neslrepo/trunk/java_project
@praveen_linux_example ~]# echo $SVN_URL| sed "s/.*///"| sed "s/$/.war/"
java_project.war
add a comment |
The problem is in your job_name=(echo $SVN_URL | awk -F "/" '{print $NF}')
line.
You are trying to use command substitution, however, you've forgotten the $
.
It should be the following in order to make bash execute the commands in brackets:
job_name=$(echo $SVN_URL | awk -F "/" '{print $NF}')
The following snippet worked perfectly for me:
#!/bin/bash
SVN_URL="http://project/svn/neslrepo/trunk/java_project"
job_name=$(echo $SVN_URL | awk -F '/' '{print $NF}')
echo $job_name.war
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%2f485103%2fshell-scripting-for-jenkins%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
4 Answers
4
active
oldest
votes
4 Answers
4
active
oldest
votes
active
oldest
votes
active
oldest
votes
The shell already provides some nice tools to do this, no need for an external command:
$ SVN_URL="http://project/svn/neslrepo/trunk/java_project"
$ echo ${SVN_URL##*/}
java_project
So all you need is:
job_name=${SVN_URL##*/}.war
add a comment |
The shell already provides some nice tools to do this, no need for an external command:
$ SVN_URL="http://project/svn/neslrepo/trunk/java_project"
$ echo ${SVN_URL##*/}
java_project
So all you need is:
job_name=${SVN_URL##*/}.war
add a comment |
The shell already provides some nice tools to do this, no need for an external command:
$ SVN_URL="http://project/svn/neslrepo/trunk/java_project"
$ echo ${SVN_URL##*/}
java_project
So all you need is:
job_name=${SVN_URL##*/}.war
The shell already provides some nice tools to do this, no need for an external command:
$ SVN_URL="http://project/svn/neslrepo/trunk/java_project"
$ echo ${SVN_URL##*/}
java_project
So all you need is:
job_name=${SVN_URL##*/}.war
answered Nov 30 at 10:49
terdon♦
128k31248423
128k31248423
add a comment |
add a comment |
It appears that basename
can also do this, despite the argument being an HTTP URL instead of a filesystem path.
echo $(basename "http://project/svn/neslrepo/trunk/java_project/").war
java_project.war
Since the man page does not mention HTTP URLs, this is probably an abuse of basename
. It seems to be a side effect of the structural similarity between an HTTP URL and a filesystem path. man 3 basename
says (emphasis mine):
The functions dirname() and basename() break a null-terminated
pathname string into directory and filename components. In the usual
case, dirname() returns the string up to, but not including, the final
'/', and basename() returns the component following the final '/'.
Trailing '/' characters are not counted as part of the pathname.
add a comment |
It appears that basename
can also do this, despite the argument being an HTTP URL instead of a filesystem path.
echo $(basename "http://project/svn/neslrepo/trunk/java_project/").war
java_project.war
Since the man page does not mention HTTP URLs, this is probably an abuse of basename
. It seems to be a side effect of the structural similarity between an HTTP URL and a filesystem path. man 3 basename
says (emphasis mine):
The functions dirname() and basename() break a null-terminated
pathname string into directory and filename components. In the usual
case, dirname() returns the string up to, but not including, the final
'/', and basename() returns the component following the final '/'.
Trailing '/' characters are not counted as part of the pathname.
add a comment |
It appears that basename
can also do this, despite the argument being an HTTP URL instead of a filesystem path.
echo $(basename "http://project/svn/neslrepo/trunk/java_project/").war
java_project.war
Since the man page does not mention HTTP URLs, this is probably an abuse of basename
. It seems to be a side effect of the structural similarity between an HTTP URL and a filesystem path. man 3 basename
says (emphasis mine):
The functions dirname() and basename() break a null-terminated
pathname string into directory and filename components. In the usual
case, dirname() returns the string up to, but not including, the final
'/', and basename() returns the component following the final '/'.
Trailing '/' characters are not counted as part of the pathname.
It appears that basename
can also do this, despite the argument being an HTTP URL instead of a filesystem path.
echo $(basename "http://project/svn/neslrepo/trunk/java_project/").war
java_project.war
Since the man page does not mention HTTP URLs, this is probably an abuse of basename
. It seems to be a side effect of the structural similarity between an HTTP URL and a filesystem path. man 3 basename
says (emphasis mine):
The functions dirname() and basename() break a null-terminated
pathname string into directory and filename components. In the usual
case, dirname() returns the string up to, but not including, the final
'/', and basename() returns the component following the final '/'.
Trailing '/' characters are not counted as part of the pathname.
answered Nov 30 at 13:50
Haxiel
1,109310
1,109310
add a comment |
add a comment |
I tried by below 2 methods and it worked fine
Method1
@praveen_linux_example ~]# SVN_URL=http://project/svn/neslrepo/trunk/java_project
[root@praveen_linux_example ~]# jobname=`echo $SVN_URL| awk -F "/" '{print $NF}'`
[root@praveen_linux_example ~]# echo $jobname.war
java_project.war
======================================================================================================
Method 2
SVN_URL=http://project/svn/neslrepo/trunk/java_project
@praveen_linux_example ~]# echo $SVN_URL| sed "s/.*///"| sed "s/$/.war/"
java_project.war
add a comment |
I tried by below 2 methods and it worked fine
Method1
@praveen_linux_example ~]# SVN_URL=http://project/svn/neslrepo/trunk/java_project
[root@praveen_linux_example ~]# jobname=`echo $SVN_URL| awk -F "/" '{print $NF}'`
[root@praveen_linux_example ~]# echo $jobname.war
java_project.war
======================================================================================================
Method 2
SVN_URL=http://project/svn/neslrepo/trunk/java_project
@praveen_linux_example ~]# echo $SVN_URL| sed "s/.*///"| sed "s/$/.war/"
java_project.war
add a comment |
I tried by below 2 methods and it worked fine
Method1
@praveen_linux_example ~]# SVN_URL=http://project/svn/neslrepo/trunk/java_project
[root@praveen_linux_example ~]# jobname=`echo $SVN_URL| awk -F "/" '{print $NF}'`
[root@praveen_linux_example ~]# echo $jobname.war
java_project.war
======================================================================================================
Method 2
SVN_URL=http://project/svn/neslrepo/trunk/java_project
@praveen_linux_example ~]# echo $SVN_URL| sed "s/.*///"| sed "s/$/.war/"
java_project.war
I tried by below 2 methods and it worked fine
Method1
@praveen_linux_example ~]# SVN_URL=http://project/svn/neslrepo/trunk/java_project
[root@praveen_linux_example ~]# jobname=`echo $SVN_URL| awk -F "/" '{print $NF}'`
[root@praveen_linux_example ~]# echo $jobname.war
java_project.war
======================================================================================================
Method 2
SVN_URL=http://project/svn/neslrepo/trunk/java_project
@praveen_linux_example ~]# echo $SVN_URL| sed "s/.*///"| sed "s/$/.war/"
java_project.war
edited Nov 30 at 18:53
terdon♦
128k31248423
128k31248423
answered Nov 30 at 15:19
Praveen Kumar BS
1,196138
1,196138
add a comment |
add a comment |
The problem is in your job_name=(echo $SVN_URL | awk -F "/" '{print $NF}')
line.
You are trying to use command substitution, however, you've forgotten the $
.
It should be the following in order to make bash execute the commands in brackets:
job_name=$(echo $SVN_URL | awk -F "/" '{print $NF}')
The following snippet worked perfectly for me:
#!/bin/bash
SVN_URL="http://project/svn/neslrepo/trunk/java_project"
job_name=$(echo $SVN_URL | awk -F '/' '{print $NF}')
echo $job_name.war
add a comment |
The problem is in your job_name=(echo $SVN_URL | awk -F "/" '{print $NF}')
line.
You are trying to use command substitution, however, you've forgotten the $
.
It should be the following in order to make bash execute the commands in brackets:
job_name=$(echo $SVN_URL | awk -F "/" '{print $NF}')
The following snippet worked perfectly for me:
#!/bin/bash
SVN_URL="http://project/svn/neslrepo/trunk/java_project"
job_name=$(echo $SVN_URL | awk -F '/' '{print $NF}')
echo $job_name.war
add a comment |
The problem is in your job_name=(echo $SVN_URL | awk -F "/" '{print $NF}')
line.
You are trying to use command substitution, however, you've forgotten the $
.
It should be the following in order to make bash execute the commands in brackets:
job_name=$(echo $SVN_URL | awk -F "/" '{print $NF}')
The following snippet worked perfectly for me:
#!/bin/bash
SVN_URL="http://project/svn/neslrepo/trunk/java_project"
job_name=$(echo $SVN_URL | awk -F '/' '{print $NF}')
echo $job_name.war
The problem is in your job_name=(echo $SVN_URL | awk -F "/" '{print $NF}')
line.
You are trying to use command substitution, however, you've forgotten the $
.
It should be the following in order to make bash execute the commands in brackets:
job_name=$(echo $SVN_URL | awk -F "/" '{print $NF}')
The following snippet worked perfectly for me:
#!/bin/bash
SVN_URL="http://project/svn/neslrepo/trunk/java_project"
job_name=$(echo $SVN_URL | awk -F '/' '{print $NF}')
echo $job_name.war
answered Nov 30 at 9:55
Fanatique
12810
12810
add a comment |
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.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- 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%2f485103%2fshell-scripting-for-jenkins%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