shell scripting for jenkins
up vote
2
down vote
favorite
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 |
up vote
2
down vote
favorite
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 |
up vote
2
down vote
favorite
up vote
2
down vote
favorite
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♦
127k31245422
127k31245422
asked Nov 30 at 9:35
user323573
111
111
add a comment |
add a comment |
4 Answers
4
active
oldest
votes
up vote
7
down vote
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 |
up vote
3
down vote
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 |
up vote
2
down vote
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 |
up vote
1
down vote
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 |
4 Answers
4
active
oldest
votes
4 Answers
4
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
7
down vote
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 |
up vote
7
down vote
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 |
up vote
7
down vote
up vote
7
down vote
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♦
127k31245422
127k31245422
add a comment |
add a comment |
up vote
3
down vote
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 |
up vote
3
down vote
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 |
up vote
3
down vote
up vote
3
down vote
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
851310
851310
add a comment |
add a comment |
up vote
2
down vote
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 |
up vote
2
down vote
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 |
up vote
2
down vote
up vote
2
down vote
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♦
127k31245422
127k31245422
answered Nov 30 at 15:19
Praveen Kumar BS
1,166138
1,166138
add a comment |
add a comment |
up vote
1
down vote
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 |
up vote
1
down vote
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 |
up vote
1
down vote
up vote
1
down vote
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