Jenkins freestyle project running as SYSTEM conversion to Pipeline project - jenkins

When I run a freestyle project in Jenkins server, here are the first two lines from the logs:
Started by user {username}
Running as SYSTEM
Question: What is SYSTEM referring to here? Is it root user?
I am trying to write pipeline script for the above mentioned freestyle project in Jenkins and here is the first few lines of its log.
Started by user {username}
[Pipeline] Start of Pipeline
[Pipeline] node
Running on Jenkins in /var/jenkins_home/workspace/test-pipeline
Question: I don't think it is Running as SYSTEM. It must be running as JENKINS user. I see some projects that I am trying to convert from free style to pipeline scripts are failing due to reasons like "acl not found" or "npm install issues". When I run free style projects, they run without any issues. Any idea how I can let the pipeline scripts Run as SYSTEM?

"By default, builds run as the internal SYSTEM user that has full permissions to run on any node, create or delete jobs, start and cancel other builds, etc." See https://www.jenkins.io/doc/book/security/build-authorization/
The "Started by" text is indicating the cause of the job being run, and does not indicate who the job is running as. Examples are "Started by user xxx" means that user xxx pressed a button or caused the event to trigger. Other examples "Push event to branch main", and "Started by timer".
Its a little odd that I only see the "Running as SYSTEM" when the job is submitted by a user from the Jenkins console. But by inserting a couple of debug prints in my automated jobs, it appears they run as the same user as the manually started jobs by default, SYSTEM.

Related

Using ssh credentials in post-build of Jenkins matrix job

We have a Jenkins matrix job with "SSH Agent" enabled in "Build Environment" with SSH credentials and a post-build action of "Execute Scripts On Matrix" with a shell command that runs ssh expecting to use the credentials stored by ssh-agent.
We recently upgraded from Jenkins v2.249.3 to v2.263.1 (and potentially upgraded some plugins at the same time, though I don't believe that we upgraded any of the ssh-related ones.) The aforementioned shell command now fails because it no longer has access to the ssh credentials it requires.
Comparing the build logs, we see a new call to ssh-agent -k in the Jenkins v2.263.1 parent job log immediately after the matrix children complete and before "[PostBuildScript] - [INFO] Executing post build scripts." that wasn't present with Jenkins v2.249.3.
It would appear that the agent is being killed before running the post-build operations by Jenkins v2.263.1 whereas it wasn't with Jenkins v2.249.3. I was unable to find a setting that controls this.
I entered JENKINS-64394 for this, but I wasn't really sure which components to label it with which I suspect mean that the right people haven't seen it. Does anyone here have any ideas?

Agent field not being populated in Jenkins Pipeline jobs

Trying to investigate Jenkins build time by node I noticed that when we switched to using jenkins-timeline our jobs stopped filling in the "Agent" field on the "Build Time Trend" page.
Old pre-pipeline jobs show the agent name in that list, but new pipeline jobs just show a blank agent field.
If I go into an individual pipeline build, I can look in the Console Output and find the Running on line to work out which agent was used, just as I can see the Building remotely on line in the console output of non pipeline builds.
Is there a way to get pipeline builds to fill in the Agent field with the machine the job was actually run on?
I believe Jenkins does not collect this information when running Pipeline jobs, as Pipeline job may run on many agents in parallel.
We wanted to have that information so we run an instance of InfluxDB and send metrics there. These metrics include the agent name, so this is available for analysis later.

Jenkins Ranorex plugin not executing test

I am new to Jenkins. I have master and slave configuration done and I have installed Jenkins on my master and want to run my ranorex test on my slave machine. All files needed for running ranorex scripts are present on my slave. When the job from the master runs, it gives error
[2019/11/18 17:04:51.686][Debug ][Logger]: Console logger starting.
[2019/11/18 17:04:51.845][Failure][TestSuite]: This operation requires an interactive window station
[2019/11/18 17:04:51.858][Debug ][Logger]: Console logger stopping.
Build step 'Execute Windows batch command' marked build as failure
Finished: FAILURE
i tried workarounds like going to Jenkins serve and selection option of user interaction.
If i only have bat file on slave of copying one folder to another and if i trigger job from master, it works. So master slave configuration does not have issue. Issue is running Ranorex GUI Test on Slave.
Jenkins needs to be running as an application not a service (which is default). Services cannot show anything with a GUI nor interact with anything with a GUI.
Disable the Jenkins service
Run Jenkins via Command Line java -jar jenkins.war
For a more detailed guide, check out the Infrastructure section of the Ranorex Jenkins integration blog.

Can I tell jenkins agent to execute job under a configured user?

I'm training a MacBook to be a jenkins agent for automation testing. On the MacBook, I logged in as user bob and installed everything needed (npm, yarn, xcode etc). Then I connected to a remote master using Java Web Start.
Because I launched the java thing in user bob, I assume jenkins pipeline jobs will also be under bob, which seems true - whoami command in pipeline echos bob. However, all dependencies cannot be found. If I echo $PATH I see a completely different result compared to echo $PATH directly on the MacBook.
I googled a bit, the problem might be that Jenkins create a new shell on everyjob. Can I tell jenkins pipeline to not to do this? I want the pipeline to use everything I configured manually for bob.
EDIT:
The main problem is jenkins pipeline's user has a different PATH. I ended up using environment directives to specify which path to use.
environment {
PATH = "/Users/bappo/.nvm/versions/node/v8.11.3/bin:$PATH"
}
What where you trying to configure? If you have parameters/configuration for your pipeline I strongly recommend to use pipeline parameters. They can either configured manually (including default values) or from the jenkinsfile.
example

Jenkins skip some jobs in chain of freestyle jobs

We got a requirement to implement CICD using Jenkins.
Here, Jenkins is running in windows machine and application server running in linux machine and build activity should happen in Linux system. So, We are connecting to linux machine using Jenkins's SSH plugin and executing jobs.
I have created list of freestyle jobs to checkout code from CVS, cleanup activity, Build , stop server, start server, Run Junit, run sonar. all these jobs are chained using 'build other projects' option in post build Action section.
Here, all jobs executes in sequential manner. But, sometimes I need to execute only few jobs like stop and start server.
So, please help me how we can randomly pick jobs which need to be run before triggering build.
Thanks,
Ganesha

Resources