10

I don't want to use Jenkins UI, instead I would like to use the command line, from command line I want to execute Jenkinsfile to the Jenkins server.

Is this possible?

Let's say I have a Jenkinsfile, If I run the Jenkinsfile, It shoud execute the Jenkinsfile from Jenkins server. Assume that the job not yet configured through Jenkins UI.

5
  • 2
    What about calling the Jenkins api using the jenkins-cli?
    – 030
    Commented Mar 21, 2018 at 5:44
  • Why do you need this? Why does the UI not work for you?
    – 030
    Commented Mar 22, 2018 at 15:33
  • @030 I'm not a fan of GUI :) Commented Mar 22, 2018 at 21:14
  • Interesting. Jenkins itself is a UI, but if you really dislike UIs then one could use the jenkins-cli.
    – 030
    Commented Mar 22, 2018 at 23:44
  • 1
    I am interested in this for testing purposes and cross-compatibility. I'd like to be able to have automatic builds based on regular multibranch/jenkinsfile plus parameterized GUI jobs when we need a manual tweak plus local CLI terminal scripts for devs to verify their part. Commented Jul 20, 2018 at 19:42

3 Answers 3

3

I've done this before. Essentially you can use the Jenkins CLI to import/export jobs, which will allow you to create and/or update a job with the definition you want to run. Be it JenkinsFile or some groovy script or whatever. Check this blog for details.

Once you (re)define the job, you will simply remotely execute it using the same Jenkins CLI. You can check the progress of the job from CLI and even read the logs to see progress. I cannot share the code, as the copyright is owned by one of my previous employers, but it is easy to recreate.

2

I assume you would like to run locally to test logic? If so there is a unit testing framework for Jenkins declarative / scripted pipeline. I have not personally used it but this would enable me to test stubbed logic locally.

Alternatively, as you're no ta fan of GUIs you could have a look at Jenkins X which has a very powerful CLI and is more gitops driven.

0

you can try using that tool, it allows to run scripts from the command line and some other thinkgs:

https://github.com/jenkinsci/jenkinsfile-runner

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.