I have several jobs running periodically on Jenkins. They are set up using the graphical interface:
Now I need to write a script that will pull information about when/how often does job run. How can I find this information?
I tried looking for this information using Remote Access API in XML, but to no avail.
Edit: Because some people find it hard to read such a short post, I would like to point out that I'm asking(literally) How to check how often is Jenkins building job? for script. Question means more or less how to get cron schedule for the job, not how to get Build number + Status[success/failed etc] + Duration from Jenkins.
Honestly, I can't see how one could even think that these are duplicates.
Here you go:
SCHEDULE=$(cat ${JENKINS_HOME}/jobs/${JOB_NAME}/config.xml | grep -A 1 ' <hudson.triggers.TimerTrigger>' | tail -1 | awk -F'[<>]' '{print $3}')
if [ -z "${SCHEDULE}" ]; then
echo "${JOB_NAME} isn't configured to run periodically"
fi
You need access to filesystem on which Jenkins has it's home.
If this approach does not suit you - you can use token authentication or password/LDAP/whatever to download the job config xml to your working directory and parse it the same way. This might be helpful if you decide to do so.
Related
I already have CICD in Jenkins automated for my team. A push to the master branch will test & deploy my team’s node app to npm. However the steps to prepare get a release are complicated and many, and right now just reside in a text file. I just copy those steps from the text document and paste them into a Unix command line to run them. I want to code something to automate/tool that release prep.
I need to run steps of commands, and pause to confirm.
I need to be able to quit at any step and resume at any step.
I need to alternate between performing steps for the computer and informational steps for displaying to people.
Nice to have:
It would be nice to have steps be relatively human readable in the code.
I would prefer to use someone else's to not roll my own.
I already know JavaScript, Bash, Make, yml
How can I best automate my pre-release steps?
You can just pass all the commands to the shell script like so in unix,
$ vi release.sh
#!/bin/bash
//Release commands here
I need to run steps of commands, and pause to confirm.
You can add the follow piece of code on the commands that you would like conformation before proceeding
echo "Do you want to continue?(yes/no)"
read input
if [ "$input" == "yes" ]
then
echo "continue"
fi
I need to be able to quit at any step and resume at any step.
I'm guessing you mean PAUSE and resume
when your shell script is running and you feel the urge to PAUSE you can use Crtl+Z to PAUSE the script and do whatever you want to do like run other scripts/process or go for a cup of coffee :)
To resume, type
$jobs -->List all jobs
[1]+ Stopped release
run fg(foreground) or bg(background)
Note: have to be in the same active shell for it to work
I need to alternate between performing steps for the computer and
informational steps for displaying to people
Add echo
echo "Going to copy the file from actual location to target location"
cp ACTUAL_LOC/file.txt TARGET_LOC/file.txt
It would be nice to have steps be relatively human readable in the
code.
This totally depends on how well you write the script file :)
I would prefer to use someone else's to not roll my own.
Do You mean rollback in sql or unix commands when a failure happens??
I have a complex screen-scraping script that I've put together that uses Selenium2, the Selenium web driver and PHP binding script, so at the end of it all, I have a PHP script that drives Selenium, which in turn fetches a URL, parses some Javascript, fills out a form, blah blah blah, and then returns the HTML that is ultimately what I'm after. It all works great on my local computer (as a development and proof-of-concept environment).
So.
For production, I need this script to run automatically three times every day. I am trying to figure out if it would be better for me to set up everything on my server (meaning: figure out how to get Firefox for Linux going, then Java, then Selenium2, etc, etc... not trivial for me; Damn it Jim, I'm a coder, not a sysadmin!), or if I can use a 3rd-party Selenium testing service like Sauce Labs' OnDemand, or any of these other cloud-based Selenium services.
Those 3rd party solutions seem like they're all set up for "unit testing," which is totally not what I'm doing. I don't know about that stuff, or using PHPUnit, or doing tests with builds, or whatever. I just want to run my straightforward PHP script 3x/day and have it talk to Selenium to drive a browser and do my screen scraping.
Are one of those 3rd party solutions a good idea for what I'm trying to accomplish, or are they overkill/too far away from my (relatively simple) goal?
First, I want to let you know that I use Selenium with Ruby so I am assuming that running your php script will start up the selenium webdriver and run your tests... I will just explain how easily run your script 3 times a day without needing to be a sysadmin master.
Linux has an extremely stable and robust command called cron which is what you will need to use. It allows you to schedule actions to happen daily/hourly/whatever.
The first thing you want to do is to go to the directory with your script. I will refer to your script as script.php.
First thing is to make sure that the top line of your script is:
#!/usr/bin/php
In the directory you will execute the following command to make your file accessible by the system:
chmod +x script.php
Now set up your cron job with the following command:
crontab -e
Then put in your job:
00 4,12,20 * * * /home/sean/script.php
00 - Means at 00 minutes.
4,12,20 - Are the hours (it is a 24 hour clock.)
The first: * - Every day
The second: * - Every month
The third: * - Every Day of the week
So this script would run every day, every week, every month at 4,noon and 8pm.
Obviously change the directory to the script on your system and set the times to whenever you want the scraping to occur.
I hope this helps!
-Appended stuff for the java/firefox-
First off, take this all with a grain of salt since I am using Ruby :)
Okay to get java/firefox running you will probably want to grab the selenium standalone. You can grab it here.
Then to run the selenium server you just:
java -jar selenium-server-standalone-2.5.0.jar
You can run put the standalone server starting in the cron job and then close it in your script file.
I´m writing a Powershell script to do a bunch of things and when finished it will be run as a scheduled task. For that reason I want to be able to check whether an older instance is still alive when I start running the script and kill the older one if it exists.
I was thinking I would use something like this:
$process = Get_Process | $name
$process.kill
But how to get the $name variable in a simple way?
Does anyone have a better suggestion?
Best regards,
Gísli
You can do this in windows scheduled task configuration. The settings depends on the OS you are using though.
EDIT: that is you can configure the task to be killed after a certain period of time (i.e. when your next one starts).
Why do you need to get the name? Get-Process returns high fidelity Process objects and you can operate on it directly.
To get a process of a particular name use $n = Get-Process notepad, say, and then do $n.kill() to kill it. If you do need to check the name again, do $n.Name. To see what properties and methods you can use, try $n | get-member
And make sure you read the manual: http://technet.microsoft.com/en-us/library/dd347630.aspx
I have this code which gives me all of the information I need regarding tasks, information etc. I have it all shelled into a VB program and I want to be able to run this from one computer and have it return the data from all computers on the domain.
I am lost as to what to add next.
Dim sCommand As String
'all processes here, ipconfig, java info, etc etc
sCommand = "java.exe -version2 > C:\Info.txt && ipconfig >> C:\INfo.txt"
Shell("cmd.exe /c" & sCommand)
I have script that will list all users on the domain, can I implement that or is there an easier way?
Edit: If I could search the entire domain for a specific file that would work too.
At the moment I just need all the data returned to a text file, I am not worried about it being sorted, or how long a process like this would take.
thanks a bunch
You could do one of two things.
1) You could use WMI to get both the network config off the remote machines and execute a process on the remote machine.
Or
2) You could use PsExec to kick off a command on a remote machine and pipe that out. I personally wouldn't use shell to execute a command as it's pretty poor really. If I was going to kick off a process locally I'd use this, and use StdOut to grab the output from the shell, parse it to give you something you can work with instead of piping the output to a file locally and then reading it later.
EDIT
So you want to do all this from one central location? If you don't want to use PSExec, you'll have to use WMI to create a process on a remote machine to run the java.exe, but you can't redirect the output, you'll have to pipe to a file and read the file in another step.
I have a .bat file shown below in which I want to redirect the whole contents present in my IDE to some text file.
D:\WindRiver\wrenv.exe -p vxworks653-2.2.3 run
D:\WindRiver\wrenv.exe -p vxworks653-2.2.3>C:\ThreePartition\output.txt
PAUSE
I am able to just get some partial output i.e I am unable to get the errors which are thrown during compilation or building process.
Is this correct or Can anyone suggest any other way??
Thanks a lot
Maddy
You can try this:
D:\WindRiver\wrenv.exe -p vxworks653-2.2.3 > C:\ThreePartition\output.txt 2>&1
You can find a good explanation here. Basically you need to redirect both stdout AND stderr to your file.
Best regards.
Your batch is redirecting all messages from wrenv.exe that are sent to the standard output.
I never used WinRiver but usually IDEs manage the console internally and don't log any messages on the standard output/error stream.
It is maybe possible to set the output of the console of the IDE though. If it is, try to set it to the standard output.
I think you want to combine both those lines into one:
D:\WindRiver\wrenv.exe -p vxworks653-2.2.3 run >C:\ThreePartition\output.txt
OK, looking at your posts here, here and here, it seems you want to log the compilation process. The command for that will be something like (all on one line):
make ThreePartition.mak >C:\ThreePartition\output.txt
Assuming there's a file called ThreePartition.mak.
The command you've been using so far is designed to simply open an interface where you can type commands, which is why you get no output. If you want to log simulation, or a kernel build, there is a file called vxworks_cli_tools_users_guide_6.6.pdf which describes the command line interface, including vxprj in full detail.
Also, are you really using a nant script to call a .vbs to call a .bat to call wrenv.exe? I'm sure there's a simpler way to do that.