Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The jenkins_script resource fails when 'groovy_path' attribute set instead of inline 'command' block. #779

Open
mromero-convoso opened this issue Dec 14, 2021 · 1 comment

Comments

@mromero-convoso
Copy link

👻 Brief Description

When attempting to use the jenkins_script resource with the groovy_path attribute set, as opposed to the command attribute set to a block of inline Groovy code, jenkins-cli returns the following error:

ERROR: This command is requesting the -remoting mode which is no longer supported. See https://www.jenkins.io/redirect/cli-command-requires-channel

I have a workaround that allows me to use a groovy file written by a template resource, which looks like this:

template ::File.join(Chef::Config[:file_cache_path], 'add_authentication.groovy') do
  source 'add_authentication.groovy.erb'
  mode '0644'
  owner 'jenkins'
  group 'jenkins'
  variables(
    password: 'somepassword'
  )
  notifies :execute, 'jenkins_script[add_authentication]', :immediately
  sensitive true
end

jenkins_script 'add_authentication' do
  command(lazy { ::File.open(::File.join(Chef::Config[:file_cache_path], 'add_authentication.groovy')).read })
  not_if 'grep ldapserver /var/lib/jenkins/config.xml'
end

🥞 Cookbook version

9.5.0

👩‍🍳 Chef-Infra Version

17.8.25

🎩 Platform details

Ubuntu 20.04 LTS

Steps To Reproduce

Within some recipe, use include the following:

template ::File.join(Chef::Config[:file_cache_path], 'add_authentication.groovy') do
  source 'add_authentication.groovy.erb'
  mode '0644'
  owner 'jenkins'
  group 'jenkins'
  variables(
    password: 'somepassword'
  )
  notifies :execute, 'jenkins_script[add_authentication]', :immediately
  sensitive true
end

jenkins_script 'add_authentication' do
  groovy_path ::File.join(Chef::Config[:file_cache_path], 'add_authentication.groovy')
  not_if 'grep ldapserver /var/lib/jenkins/config.xml'
end

You should get the error mentioned above during convergence.

🚓 Expected behavior

The executed jenkins-cli command should look something like this:

java -jar "/tmp/kitchen/cache/jenkins-cli.jar" -s http://localhost:8080 -webSocket -auth @<some cli file> groovy = < /tmp/kitchen/cache/add_authentication.groovy

It currently looks something like this:

java -jar "/tmp/kitchen/cache/jenkins-cli.jar" -s http://localhost:8080 -webSocket -auth @<some cli file> groovy < /tmp/kitchen/cache/add_authentication.groovy

The additional = sign in the first example above is what seems to allow it to behave the way it should, without throwing the error about the -remoting option no longer being supported.

@mbaitelman
Copy link
Contributor

When I looked into this there are 2 different methods being called for groovy execution, likely needs to be unified in some way.
https://github.com/sous-chefs/jenkins/blob/main/libraries/_executor.rb#L69
https://github.com/sous-chefs/jenkins/blob/main/libraries/_executor.rb#L152

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants