Coder Social home page Coder Social logo

Comments (8)

lhupfeldt avatar lhupfeldt commented on August 27, 2024

Hi Aleksey,

Did you create a jenkins user to run the jobs? If you have a user with
permission to run the job and initialize the jankinsapi like below, it should work.

api = jenkins.Jenkins(baseurl=, username=, password=)

from jenkinsflow.

lechat avatar lechat commented on August 27, 2024

No, it doesn't work.

From some version of Jenkins job can be only triggered by POST request. Urllib2, used by jenkinsapi, will only generate POST request if there are non empty parameters has been passed to function used to access URL.

Here what happens:

  1. jenkinsflow passes None as securitytoken parameter to jenkinsapi.job.invoke
  2. jenkinsapi.job.invoke passes token=None to jenkinsapi.job.get_build_triggerurl, so it will return tuple: url with "$JOB_NAME/build" and params=None
  3. jenkinsapi.job.invoke will call jenkinsapi.job.hit_url with no parameters
  4. jenkinsapi.job.hit_url will pass empty parameters to urllib
  5. urllib will issue GET request to Jenkins
  6. Jenkins will reply with
<!DOCTYPE html><html><head>


    <title>Form post required [Jenkins]</title><link rel="stylesheet...

If I try to pass "token" as a parameter to a job, on step 2 above result will be a tuple: url with "$JOB_NAME/buildWithParams" and params="token=token_value".

This is wrong because job doesn't have parameters and Jenkins will reply with error 500: Job doesn't have parameters

Hope this helps!

from jenkinsflow.

lhupfeldt avatar lhupfeldt commented on August 27, 2024

Which versions of Jenkins/Jenkinsapi are you at now?

from jenkinsflow.

lhupfeldt avatar lhupfeldt commented on August 27, 2024

Hi Aleksey,

It is the version of jenkinsapi available via pip that is outdated. Sorry for not realizing this earlier.
Instead install the latest jenkinsapi from git, then it works.

git clone https://github.com/salimfadhley/jenkinsapi.git
sudo python ./setup.py install

I tested with latest git jenkinsapi 97051dff04f50f39502b7c5c18f22940dda72264 and Jenkins ver. 1.514 available today.

from jenkinsflow.

lechat avatar lechat commented on August 27, 2024

Still doesn't work for me.

Jenkins ver. 1.509.1, jenkinsapi installed from github

Perhaps this has been fixed in later Jenkins? Will try it now.

Started by user anonymous
[EnvInject] - Loading node environment variables.
Building in workspace /devshared/home/maleksey/jenkins-test/workspace/TEST-jenkinsflow
[TEST-jenkinsflow] $ /devshared/home/maleksey/virtualenv-1.9.1/jenkins/bin/python /tmp/shiningpanda4074820405597151072.py
== Legend ==
Serial builds: []
Parallel builds: ()
Invoking (w/x,y/z): w=current invocation in current flow scope, x=max in scope, y=total number of invocations, z=total max invocations
Elapsed time: 'after: x/y': x=time spent during current run of job, y=time elapsed since start of outermost flow

Queuing jobs for serial run: [
   Queuing job: ADMIN-flow-1 'ADMIN-flow-1' Status IDLE - latest build: ADMIN-flow-1 #5
   Queuing jobs for parallel run: (
      Queuing job: ADMIN-flow-2 'ADMIN-flow-2' Status IDLE - latest build: None
      Queuing job: ADMIN-flow-3 'ADMIN-flow-3' Status IDLE - latest build: None
   )

   Queuing job: ADMIN-flow-1 'ADMIN-flow-1' Status IDLE - latest build: ADMIN-flow-1 #5
]



Invoking (1/1,1/1): ['ADMIN-flow-1', ('ADMIN-flow-2', 'ADMIN-flow-3'), 'ADMIN-flow-1']

Invoking (1/1,1/1): http://sabrebuild1.uk.standardchartered.com:8180/job/ADMIN-flow-1 - /build
Traceback (most recent call last):
  File "/tmp/shiningpanda4074820405597151072.py", line 42, in <module>
    main()
  File "/tmp/shiningpanda4074820405597151072.py", line 38, in main
    ctrl1.invoke('flow-1')
  File "/devshared/home/maleksey/src/jenkinsflow/jobcontrol.py", line 413, in __exit__
    self.wait_for_jobs()
  File "/devshared/home/maleksey/src/jenkinsflow/jobcontrol.py", line 383, in wait_for_jobs
    last_report_time = self._check(start_time, last_report_time)
  File "/devshared/home/maleksey/src/jenkinsflow/jobcontrol.py", line 331, in _check
    last_report_time = job._check(start_time, last_report_time)
  File "/devshared/home/maleksey/src/jenkinsflow/jobcontrol.py", line 142, in _check
    self.job.invoke(invoke_pre_check_delay=0, block=False, params=self.params if self.params else None)
  File "build/bdist.linux-x86_64/egg/jenkinsapi/job.py", line 125, in invoke
AssertionError: The job did not schedule.
Build step 'Custom Python Builder' marked build as failure
Notifying upstream projects of job completion
Finished: FAILURE

from jenkinsflow.

lechat avatar lechat commented on August 27, 2024

This problem only happens if Jenkins security is switched on.

If Jenkins is secured, then /build URL will be required to be triggered by POST with security token. If Jenkins in not secured - then /build is triggered by GET.

But problem with jenkinsflow still remains. There shall be an option to specify security token for build.

from jenkinsflow.

lhupfeldt avatar lhupfeldt commented on August 27, 2024

Hi Aleksey,

Today is a holiday here, but I will implement a token option tonight when I
get home from my family visit.

from jenkinsflow.

lhupfeldt avatar lhupfeldt commented on August 27, 2024

Hi Aleksey,

I've added a 'securitytoken' argument to the the serial/parallel flow constructors. It can be specified at the top level flow and possibly overridded in child flows. The flow will put the token on the job invocations.

from jenkinsflow.

Related Issues (19)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.