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

Allow specifying a different shell command other than /bin/sh #287

Merged
merged 2 commits into from
Mar 6, 2018

Conversation

lbouquety
Copy link

We need to be able, in our containers, to load profile files (.bash_rc, .profile, ...) at runtime. /bin/sh, while it's often just a link to /bin/bash puts you in a compatibility mode that doesn't load these files.

We run this Jenkins plugin against an OpenShift cluster that, by default, runs containers with an undefined UID. Being able to load variables from "profile" files is critical for us.

The implementation is retro compatible with the already written jenkinsfiles, but let's you override the interpreter you will use to run commands in your container (in our case, we mostly want to use bash).

An example of Jenkinsfile with the modification:

podTemplate(name: 'maven', label: 'maven', containers: [
  containerTemplate(name: 'maven', image: 'maven:latest', ttyEnabled: true, command: 'cat', alwaysPullImage: true),
  containerTemplate(name: 'jnlp', image: 'openshift/jenkins-slave-base-centos7', args: '${computer.jnlpmac} ${computer.name}', alwaysPullImage: true),
  ]) {

  node('maven') {
    stage('Build a Maven project') {
      container(name:'maven', shell:'/bin/bash') {
        sh 'mvn -version'
      }
    }
  }
}

@carlossg
Copy link
Contributor

doesn't this achieve the same result?

  container('maven') {
    sh """#!/bin/bash
      mvn -version
    """
  }

@lbouquety
Copy link
Author

It does achieve the same result, but the resulting Jenkinsfile with my patch looks more developer friendly, IMHO.

@carlossg
Copy link
Contributor

I think I'm ok adding this. It's just missing some docs and using the shell param in one of the non-declarative tests to ensure it works

@carlossg carlossg changed the title Change shell command Allow specifying a different shell command other than /bin/sh Feb 21, 2018
@carlossg carlossg changed the title Allow specifying a different shell command other than /bin/sh Allow specifying a different shell command other than /bin/sh Feb 21, 2018
@nodefourtytwo
Copy link

The test failure seems unrelated to this PR, could it be replayed or investigated?

@carlossg carlossg merged commit c156507 into jenkinsci:master Mar 6, 2018
@carlossg
Copy link
Contributor

carlossg commented Mar 6, 2018

merged , thanks

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

Successfully merging this pull request may close these issues.

3 participants