Jenkins: How is Script From Different Repo Being Included? - linux

I am trying to debug a shell script that is executed via a Jenkins job. The first thing the script does is include another script that is in a completely different repo. My instinct is telling me that the user that Jenkins is executing the script from has access to the directory for the other repo through $PATH or some other similar mechanism, but nothing I’m seeing indicates this.
I’ve looked over variables in http://$host/systemInfo, tried logging on to the Linux box, switched to various users and searched through command history for each, looked at $PATH variable for each, and even tried executing a test shell script with the same include as different users. Still not seeing anything to indicate how Jenkins is able to include a file from a different repo and have not been able to get the include to work in my test script.
My main questions are:
How can I determine what user Jenkins is executing the original shell script as? I would assume user 'jenkins' but I'm not able to get the include to work in my test script executing as this user.
How is Jenkins able to include a script from a different repo?
I'm sure I'm just running into some fundamental Jenkins ignorance on my part but not finding answers. Thanks in advance for any insight.

Finally found the answer and it seems really obvious now that I see it. The Jenkins server that the job runs from has a PATH environment variable defined in the server config in the Jenkins interface. This PATH points to the directory containing the external script.

Related

boto3 describe_images empty (jenkins/packer)

I am running packer via a jenkins pipeline and want to delete the ami afterwards.
I am using a small python3/boto3 script to do that.
However, when calling describe_images I get an empty list. No errors (via debug).
If I run the same script via the same docker based agent (on a ec2 jenkins node) but from a different pipeline, it works.
I also do not have issues on another project with similar settings.
Sometimes, intermittently it will work, but seldom.
I can rule out a general config issue as the same script works perfectly on the same systems (just a different jenkins pipeline).
I can also rule out general issue with the jenkins pipeline, as it will intermittently work - without changes.
What am I missing?
Yikes, this was a stupid mistake on my side. So my script to fetch the ami-id from the packer manifest.json was not returning the correct ami-id (I assumed I'd only find one ami-id in that file).

Using jenkins to modify files

I've just started to get to grips with Jenkins. It currently performs the following tasks:
Pulls the latest codebase from git
Uploads the codebase via sftp to my environment
Sends a notification email to the testers and the PM to inform them of a completed deployment.
However for it to be truly useful I need it to perform two more tasks:
Delete the robots.txt and .htaccess file which exists in the git repo and replace it with a predefined version which is specific for the server
Go through all the code and remove specific code-blocks (perhaps something in between comments: eg. /** Dev only **/ Code to be removed goes here /** Dev only **/ or something like that).
Are there any plugins which can accomplish these things or would I have to read up on writing groovy scripts for this sort of thing (I don't know anything about those yet).
On a related note: I'd also love it if it could combine kit and SASS files, however I can't see a plugin for these things, however I assume I can just install compass on my build server and then run it via command line in the build process. Is that correct?
Instead of putting your build tasks directly into the Jenkins job, I recommend writing a build script to accomplish your publishing/deployment tasks.
Jenkins is great for having a single point of automation that is easy to run, can publish build results, and can track successes and failures. In my experience though, you're better off not putting your individual tasks and configuration steps into the Jenkins job configuration. At some point, you'll want to be able to run this job without Jenkins, either because you want to test local changes, or you want to handle multiple jobs and trying to keep job configurations in sync is not fun, or because you're moving to another build/deployment system. Also, putting the build script into a file allows you to put it into your source control system and track changes.
My advice: choose a scripting language (Python, Ruby, Perl, whatever you're comfortable with) or build system (SCons and Rake are options) and write a build script. In Python Ruby, and Perl, it's easy to manipulate files (#1) and all have a wide choice of templating systems that will accomplish #2. Then the Jenkins job becomes running your build script on the command line (or executing through a language-specific builder). And the build script can include running any of the tasks that you decide to put in your build (compass, etc).

How to place Email-Ext groovy script on the jenkins file system

I need to dynamically modify the notification e-mail recipients based on the build, so I'm using a groovy script. I want this script to be available to all jobs, so I want it to reside on the Jenkins file system and not within each project. It can be either in the recipients fields (using ${SCRIPT,...}) or in the pre-send script. A short (fixed) script that evaluates the master script is also good, as long it is the same for all projects.
You should try Config File Provider plugin. It works together with the Credentials configuration of Jenkins.
Go to Manage Jenkins > Managed files
Click Add a new Config
Select Groovy file
Enter the contents of your script
Your script will now be saved centrally on Jenkins, available to master/slave nodes.
In your Job Configuration:
Under Build Environment
Check Provide Configuration file
Select your configured groovy File from dropdown
Set Variable with a name, for example: myscript
Now, anywhere in your job, you can say ${myscript} and it will refer to absolute location of the file on filesystem (it will be somewhere in Jenkins dir).
My impression it that you would probably want to completely switch to Jenkins pipelines where the entire job is groovy file (Jenkinsfile) in the root of the repository.
Email-Ext already supports it even if it may be lacking some documentation.
https://jenkins.io/doc/pipeline/steps/email-ext/

Hudson : Scheduling a build without a tag and generate a report

How can I schedule a build without tag over Windows, Linux and WCE in Hudson using a shell script and generate a report that will be sent to a specified server?
And so the conditions are :
1. How can I create the build without creating a new tag?
2. How is it possible to excute .sh over windows and WCE (Windows Mobile), is it simply by going through Cygwin? Moreover, having a cross-platform (3 platforms) build does it mean that I must run the build 3 times?
3. How to generate a report and save it in a directory of a server that I'm authorized to access to?
I know that I asked many questions at once. It is because this is my first use of Hudson and these are kind of details. Moreover, I don't want to make a mistake by creating new tags during my tests. The 1st and 3rd questions are the most important. If anyone gives me the right answer to them, I'll choose it as the right answer.
Thank you a lot.
first, people nowadays mostly use jenkins instead of hudson (open source, better support)
build can be started manually in hudson / jenkins, just click the green arrow. It will create a new build but won't change your repository (unless the last step of your build is creating a tag, in that case, just remove that step for testing)
Usually, .sh scripts run in shell excecutables (ash, sh, bash, csh...) and are not supported of the shell on windows. You'll have to go through cygwin or have a platform specific build command
kind of not clear for me. If you use jenkins to build a matric build (with the matrix axis being your target platform), you'll have automatically a nice report in jenkins itself (status of each build). You can keep artifacts (use post-build action : archive the artifacts) or use another plugin to publish the file you like (exemple : ftp reporting)
Sorry not being able to be more precise, that's how far I understand your questions.

jenkins script console: list of available jenkins methods?

I would like to use the jenkins script console some more.
Where do I have to look in order to find a list of available Objects/Methods that I can use via groovy? Is there something online? Should I browse the source on Github? Where would I start?
Like in this example, how would I have known that hudson.model.Hudson.instance.pluginManager.plugins exists and is ready to be called from the jenkins script console?
println(hudson.model.Hudson.instance.pluginManager.plugins)
Thanks!
You are looking for Jenkins Main Module API.
You may find this answer helpful in getting yourself on your way.
You can enter a groovy script in the script console.
The complete API can be found at the jenkins javadoc.

Resources