How to execute grovvy script remotely on Jenkins server?

A Jenkins Admin can execute groovy scripts remotely by sending an HTTP POST request to /script/ url or /scriptText/.

curl example via bash

curl -d "script=<your_script_here>" https://jenkins/script
# or to get output as a plain text result (no HTML)
curl -d "script=<your_script_here>" https://jenkins/scriptText

curl submitting groovy file via bash

curl --data-urlencode "script=$(< ./somescript.groovy)" https://jenkins/scriptText

curl submitting groovy file providing username and password via bash

curl --user 'username:password' --data-urlencode "script=$(< ./somescript.groovy)" https://jenkins/scriptText

Jenkins CLI offers the possibility to execute groovy scripts remotely using groovy command or execute groovy interactivelly via groovysh.

java -jar jenkins-cli.jar -noCertificateCheck -s https://10.0.0.91/ groovy disableEnableJobsMatchingPattern.groovy jobPattern=build_git_auto disableOrEnable=disable --username 12345 --password banana

Reference
https://wiki.jenkins.io/display/JENKINS/Jenkins+Script+Console

 

 

Tagged : / / /

Expect script for Windows

vijayakumar.cm created the topic: Expect script for Windows
Hi,

I’m executing one expect script from windows to do automatic FTP to Unix server.

Error msg:-
D:\expect>tclsh85 telnet.exp
Connecting to 10.118.215.14 to upload the latest build.
invalid command name “spawn”
while executing
“spawn ftp $hostname”
(file “telnet.exp” line 17)

do anyone have any idea about this error/expect script for windows?

Regards,
Vijay

Tagged :

Ant script with EMMA code-coverage

scmuser created the topic: Ant script with EMMA code-coverage

Ant script with EMMA code-coverage so it can find runtime coverage data?

<taskdef resource="emma_ant.properties">
    <classpath>            
        <pathelement location="lib/emma.jar" />
        <pathelement location="lib/emma_ant.jar" />
    </classpath>
</taskdef>
 
<target name="compile">
    <mkdir dir="build"/> <!-- vytvori adresar build -->
    <mkdir dir="build/classes"/>
    <mkdir dir="build/test"/>
    <javac destdir="build/classes" srcdir="src" debug="true" /> <!-- prelozi zdrojove kody -->
    <javac destdir="build/test" srcdir="test"> <!-- prelozi testy -->
        <classpath> <!-- pro prelozeni testu je potreba junit a prelozena aplikace -->
            <pathelement location="lib/junit-4.5.jar" />
            <pathelement location="build/classes" />
        </classpath>
    </javac>
</target>
 
<target name="build" depends="compile">
    <jar destfile="tetris.jar" basedir="build/classes"> <!-- zabali aplikaci do jaru -->
        <manifest>
            <attribute name="Main-Class" value="tetris.Main"/>
            <attribute name="Class-Path" value="lib/mysql-connector-java-5.1.6-bin.jar lib/derbyclient.jar"/>
        </manifest>
    </jar>
</target>
 
<target name="jar" depends="build"></target>
 
<target name="run" depends="compile">
    <java classname="tetris.Main" classpath="build/classes">  <!-- spusti aplikaci -->
        <classpath>
            <pathelement location="lib/mysql-connector-java-5.1.6-bin.jar" />
            <pathelement location="lib/derbyclient.jar" />
        </classpath>
    </java>
</target>
 
<target name="instrument" depends="compile">
    <mkdir dir="build/instrumented"/>
 
    <emma verbosity="verbose"> <!-- vytvori tridy upravene pro sledovani coverage -->
        <instr instrpath="build/classes"
                destdir="build/instrumented"
                metadatafile="build/metadata.emma"
                merge="true" />
    </emma>
</target>
 
<target name="test" depends="instrument">
    <mkdir dir="reports" />
    <mkdir dir="reports/junit" />
 
    <junit printsummary="yes" haltonfailure="no" fork="true"> <!-- pusti JUnit testy -->
        <classpath>
            <pathelement location="build/test" />
            <pathelement location="build/classes" />
            <pathelement location="build/instrumented" />
            <pathelement location="lib/junit-4.5.jar" />
            <pathelement location="lib/emma.jar" />
            <pathelement location="lib/emma_ant.jar" />
        </classpath>
 
        <formatter usefile="false" type="brief" />
        <formatter type="plain"/>
 
        <batchtest fork="yes" todir="reports/junit"> <!-- reporty budou v adresari reports/junit -->
            <fileset dir="test">
                <include name="**/TetrisSuite.java"/>
            </fileset>
        </batchtest>
        <jvmarg value="-Demma.coverage.out.file=build/coverage.emma"/>
        <jvmarg value="-Demma.coverage.out.merge=true" />
    </junit>
 
    <emma enabled="true" verbosity="verbose"> <!-- vygeneruje report emmy -->
        <report sourcepath="src">
            <fileset dir="build" includes="*.emma" />
 
            <html outfile="reports/coverage.html" />
        </report>
    </emma>
</target>
 
<target name="clean">
    <delete dir="build"/> <!-- smaze adresar build -->
    <delete dir="reports"/>
    <delete file="tetris.jar"/>
</target>

processing input file […NetBeansProjects/Tetris3/build/metadata.emma] …
loaded 25 metadata entries
1 file(s) read and merged in 5 ms
nothing to do: no runtime coverage data found in any of the data files

Tagged :

Script for time stamp update.

scmuser created the topic: Script for time stamp update.

write a batch Script for time stamp update?

sgadmin replied the topic: Re:Script for time stamp update.

data=data.txt
tfile=`cat data.txt |wc -l`


for (( i = 2 ; i <= tfile ; i++ ))
do

mfile=`cat $data |head -$i|tail -1|tr -s ” ” ” ” |cut -f8 -d” “`
mdate=`grep -i $mfile $data|tr -s ” ” ” “|cut -f6,7 -d” “`
myy=`echo $mdate |cut -b 1-4`
mon=`echo $mdate |cut -b 6-7`
mdd=`echo $mdate |cut -b 9-10`
mhh=`echo $mdate |cut -b 12-13`
mmin=`echo $mdate |cut -b 15-16`
mresult=`echo $myy$mon$mdd$mhh$mmin`
touch -t $mresult $mfile

done

Tagged :

Function in vb script

rajani created the topic: function in vb script

Develop a function that accepts a string of names separated by comma add those names in an array and display the names added in the array.

rajeshkumar replied the topic: function in vb script

Welcome to board….

try following snippet…

Sub Funstr("str1", "str2")

a=Array(str1,str2)
document.write(a(0))
document.write(a(1))
End Sub

I would recommend you going through this url as well to learn more about it……

www.functionx.com/vbscript/Lesson06.htm

Regards,
Rajesh Kumar
Twitt me @ twitter.com/RajeshKumarIn

rajani replied the topic: function in vb script

it won’t work
i have write
“Develop a function that accepts a string of names separated by comma (example given below), add those names in an array and display the names added in the array”

Example: rajani; Disha; Dhara; Hunny ;moon
without using split function
can i use mid function

rajani replied the topic: function in vb script

i am able to display name but with comma
Dim fruits()
ReDim fruits(100)
nofruits=0
‘we do not know how many fruit names we are going to enter and so, we have declared the array size as 100
For i=0 to 100
fruits(i)=inputbox(“Enter the name of a fruit separated by comma”)
ans = MsgBox(“Do you want to continue”, vbYesNo, “Confirm Continuation…”)
If ans=vbNo Then
Exit For
End If
nofruits=nofruits+1
Next
ReDim Preserve fruits(nofruits)
‘Redim keyword resets the number of elements that can be accommodated in the array.

fruitnames=””

For each fruit in fruits
‘Using For Each Next we have displayed all the names of the fruits which was entered and kept in fruits array.
‘For Each Next extracts the fruit names stored in the array and msgbox displays the output.

fruitnames=fruitnames&fruit&vbnewline
Next

msgbox fruitnames

rajani replied the topic: function in vb script

any suggestion

rajani replied the topic: function in vb script

dim Array, Str1,X
Str1 = “Neha; Swati; Disha; Sonya; Dhara”
Array = split(Str1,”;”)
for each x in Array
message = message & x & vbCRLF
next
msgbox message

Tagged :

How to read a .properties file through script

rajeshkumar created the topic: How to read a .properties file through script

The easy way to do it is to note that a Java properties file has the same format as a basic shell script.

However, there’s a trick to it. If you just run the properties file like so:

sh appl.properties

The assignments will be made at the sub-level, then discarded when the properties file (script) ends execution.

So to get the properties in a calling script, you need to use the “source” command:

. appl.properties

Note that the space after the initial dot is very important!

To reference shell variable assignments, you use the “$” to indicate variable substitution.

So, to put it all together:

# #!/bin/sh
# # Sample shell script to read and act on properties
#
# # source the properties:
# . appl.properties
#
# # Then reference then:
# echo "My name is $name and I'm $age years old."

Regards,
Rajesh Kumar
Twitt me @ twitter.com/RajeshKumarIn

Tagged :

How to perl script to extract data

mnanjala created the topic: how to perl script to extract data

Hi All,

Below are the contents in the test.txt file

id name adress
1 rajesh pune
2 pravin puttur
3 bani banglore

Now can anybody write perl script to extract data based on id ?

Example if id is 1 it should print rajesh from pune and so on

Thanks
Pravin

Tagged :

Make sure script is running using korn shell

scmuser created the topic: Make sure script is running using korn shell

If you have developed a script using the Korn shell, how will you make sure the script will use that shell even if login shell is different?

renjith replied the topic: Re: Make sure script is running using korn shell

begin shell script with Shabang/interpreter line

#!/bin/ksh

rajeshkumar replied the topic: Re: Make sure script is running using korn shell

There are 2 ways to run a script with specific shell no matter if login shell is different..

Method 1:
Use following before any shell script…
#!/bin/ksh

Method 2:

Execute shell script with ksh
Regards,
Rajesh Kumar
Twitt me @ twitter.com/RajeshKumarIn

Tagged :