I have written a shell script with commands like:
version=$1;
sed -i 's/def version = ".*"/def version = "'$version'"/' $file;
grails package-plugin;
echo -n 'Enter description of new version: ';
read desc;
git commit -m "$desc";
I want to convert it into a groovy script i.e, to create a custom grails-command that does the same thing, using GANT.
I searched a lot. But, I'm unable to find the proper methods in Apache Ant API to run a linux command like above.
Please suggest me a solution to my shell-script code with equivalent GANT script
Atleast suggest me where to start with to achieve my task.
Thank you very much in advance...
Well at last, I have figured it out how to perform the above said task.
Thanx to Grails documentation and Apache Ant tasks manual . .
After taking a whole day time, I observed that for any task to be performed:
one can refer to Apache Ant manual first,
Find it in the index,
and then knowing its usage along with necessary arguments and examples given in XML,
Then observe how XML syntax is converted to corresponding Groovy script i.e., GANT script
For e.g., observe the mkdir task and its corresponding usage in grails doc example i.e., use ant variable, then . task-name [ arguments-map ]
For those shell commands which don't have a direct task in Apache Ant manual, use exec() to run the command
That's it ... task complete :)
Related
I encounter the issue that I have a parameterized project with several string parameters, e.g., "VARIABLE_A", and that Jenkins doesn't know them anymore when executing a shell script in the Build section, i.e., there is simply no value.
This is very bizarre and I am convinced this should work using a string parameter (variable) in these ways:
"echo $VARIABLE_A"
"python3 $PATH/abc.py $VARIABLE_A"
...
but there is no values anymore.
echo-command does not print anything and the Python script misses the value as VARIABLE_A is apparently empty.
Perhaps someone has an idea ?
Thanks
Rainer
PS
Jenkins version is "2.277.2".
I'm looking for a way to use an output from shell as a jenkins parameter but in pipeline, don't want to use any of UI plugins.
For example I want to use output from command
ls /home
as a choice parameter (so I would be able to choose users from the list), is it possible to do something like that?
It must be done in pipeline, I'm not looking for some plugins which allow you to do something like that, but you need to do all in UI, if plugin support pipelines then it's also ok.
For a pipeline to run, its parameters need to be completely defined before the pipeline is started.
For the pipeline to parse the output of ls /home, it needs to run and allocate a node and a workspace, which can only happen after the pipeline is started.
So you are in a kind of a chicken-and-egg problem, where you need to run some code before you start a pipeline, but you can't run pipeline before you run that code.
So your issue boils down to "How can I run some arbitrary Groovy script before I start my pipeline?"
There are two options for this:
ActiveChoice plugin allows you to define a parameter that returns a script. Jenkins will then run the script (don't forget to approve it) in order to show you your "Build with parameters" page. Debugging this is notoriously hard, but this can go to great lengths.
Alternatively, you may want to run a scripted pipeline before you run the Declarative (main) one, as outlined e.g. in this answer. This may look a bit like this:
def my_choices_list = []
node('master') {
stage('prepare choices') {
// read the folder contents
def my_choices = sh script: "ls -l /home", returnStdout:true
// make a list out of it - I haven't tested this!
my_choices_list = my_choices.trim().split("\n")
}
}
pipeline {
parameters {
choiceParam('OPTION', my_choices_list)
I have a bunch of bash scripts that I run sequentially. I'm going to consolidate to a single script but there's one part that's a bit tricky. Specifically, script C launches a Google Compute Engine job and I only want script D (the one immediately following it) to execute once that's done.
Is there a good way of doing this?
In case it helps, my new script would be:
source script_A.sh
source script_B.sh
source script_C.sh
**wait until cloud job has finished**
source script_D.sh
Thanks!
After gcloud ... & is called, use gcloudpid=$! (I don't think you have to export, but it wouldn't hurt) to grab its pid. then your main script will be
source script_C.sh
wait $gcloudpid
source script_D.sh
It's possible to write shell scripts in Scala by starting a text file with:
#!/bin/sh
exec scala "$0" "$#"
!#
To ease script creation, I would like to write an executable called scalash (perhaps a BASH script) allowing to shorten Scala script header to just one line:
#!/bin/scalash
Is it possible ? Extra points if I can pass optional parameters to scalash, for instance to add classpath dependencies.
In Scala 2.11, you can do it as follows (exactly as with most other languages):
#!/usr/bin/env scala
println(args.mkString(" "))
In Scala 2.9.0.1, you can simply create the following script:
test.scala
#!/usr/bin/scala
!#
println(args.mkString(" "))
and make it executable. (change the first line to path to your executable)
Usage:
# ./test.scala Hello world!
Hello world!
See this pull request (was this). There's no issue associated with it -- if you feel like it, you could open an issue and comment on the pull request.
You can also use SBT to start the scripts. See information about scalas here.
EDIT
The pull request was accepted, so this should work:
#!/usr/bin/env /path/to/scala
etc
I added bash completion for Maven following the docs:
http://maven.apache.org/guides/mini/guide-bash-m2-completion.html
Everything works well except for goals that use a colon. For instance, instead of
mvn eclipse:eclipse
completion escapes the colon
mvn eclipse\:eclipse
Any suggestions how this can be fixed? I'm using Ubuntu 8.10 (2.6.27-17-generic) and
$ bash -version
GNU bash, version 3.2.39(1)-release (i486-pc-linux-gnu)
From Bash FAQ E13.
Just after the complete command in the script you linked to, issue this command to remove the colon from the list of completion word break characters:
COMP_WORDBREAKS=${COMP_WORDBREAKS//:}
Here is a related question and another suggested solution:
How to reset COMP_WORDBREAKS without effecting other completion script?
As stated before, the simplest solution is to alter COMP_WORDBREAKS. However, modifying COMP_WORDBREAKS in your completion script is not safe (as it is a global variable and it has the side effect of affecting the behavior of other completion scripts - for example scp).
Therefore, bash completion offers some helper methods which you can use to achieve your goal in a better and more safer way.
Two helper methods were added in Bash completion 1.2 for this:
_get_comp_words_by_ref with the -n EXCLUDE option
gets the word-to-complete without considering the characters in EXCLUDE as word breaks
__ltrim_colon_completions
removes colon containing prefix from COMPREPLY items
(a workaround for http://tiswww.case.edu/php/chet/bash/FAQ - E13)
So, here is a basic example of how to a handle a colon (:) in completion words:
_mytool()
{
local cur
_get_comp_words_by_ref -n : cur
# my implementation here
__ltrim_colon_completions "$cur"
}
complete -F _mytool mytool
Using the helper methods also simplifies the completion script and ensures that you get the same behavior on any environment (bash-3 or bash-4).
You can also take a look at man or perl completion scripts in /etc/bash_completion.d to see how they use the above helper methods to solve this problem.
Any suggestions how this can be fixed? I'm using Ubuntu 8.10 (2.6.27-17-generic) and
Dennis answer is definitely correct.
But for the record, there is a logged issue (MNG-3928) to improve the documentation about the Maven integration with bash. The issue has a script attached which is an improved version of the one currently online and just works. You might want to give it a try.
Personally, I use the Bash Completion script from Ludovic Claude's PPA (the one that is bundled into the maven package from Ubuntu) that I download directly from bazaar (her e is a direct download link to the HEAD revision). It is just awesome.
I'd go with the Maven2 Bash Completion File at willcodeforbeer.com.
works great
handles colons
doesn't muck up global variable COMP_WORDBREAKS (thereby breaking scp, etc)
easy to edit and understand
Hope that helps!