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

Issues with Kubernetes #38

Open
shankarinece opened this issue Nov 20, 2019 · 6 comments
Open

Issues with Kubernetes #38

shankarinece opened this issue Nov 20, 2019 · 6 comments

Comments

@shankarinece
Copy link

shankarinece commented Nov 20, 2019

Hi,
Not able to see the sonar-scanner binary while using the image in Kubernetes environment with jnlp slaves.
the directory /usr/local/bin/ doesn't have the binary or the link.
The Jenkinsfile looks like the one below.
pipeline {
agent none
stages {
stage('SQTest') {
agent {
kubernetes {
label 'sample-app'
defaultContainer 'jnlp'
yamlFile 'cloudprovider.yaml'
}
}
steps {
sh "sonar-scanner -Dproject.settings=testInputs/sonar-project.properties"
}
}
}
}

The cloudprovider.yaml has the image newtmitch/sonar-scanner:alpine and command['cat']

Any suggestions?
Thanks

@newtmitch
Copy link
Owner

Sorry, I'm not really familiar enough with Jenkins to make suggestions on how to properly run Sonar in K8S with a Jenkins pipeline.

@serut
Copy link

serut commented Nov 13, 2020

Here is some example of Declarative Pipeline without k8s we use. You can see the entrypoint hack that is a little bit pain in the ***, most of Docker images have a docker-entrypoint.sh that does nothing as entrypoint, not the cli itself.

        stage('Sonar') {
            when {
		        expression { BRANCH_NAME ==~ /(master|develop.*|feature.*|V-[0-9]+\.[0-9]+)/ }
            }
            agent {
                docker {
                    reuseNode true
                    image 'newtmitch/sonar-scanner:3.3'
                    args '-e CURRENT_WORKSPACE=${WORKSPACE} --entrypoint='
                }
            }
            steps {
                sh 'TAG=$(${CURRENT_WORKSPACE}/jenkins/nginx/getPackageVersion.sh ${CURRENT_WORKSPACE})'
                sh '/usr/local/bin/sonar-scanner \
                    -Dsonar.projectVersion=${TAG} \
                    -Dsonar.branch.name=${BRANCH_NAME} \
                    -Dsonar.projectBaseDir=/${CURRENT_WORKSPACE} \
                    -Dsonar.host.url=http://sonarserver:9000/'
            }
        }

Jenkins runs the agent.docker.image with the cat cli as args to blocks the image when it boots so we absolutly need to remove the entrypoint. Then Jenkins runs each commands inside the container with full control.
As Jenkins is already in a docker, I need to clone the CURRENT_WORKSPACE var but that's just another layer of complexity not related to this issue. The TAG is computed inside the container using some shell to show we can do everything we want

source : https://github.com/RegardsOss/regards-frontend

@newtmitch
Copy link
Owner

thanks @serut. I just recently refactored the project a bit and moved the Dockerfile away from the ENTRYPOINT approach and instead went back to a purely CMD-based launch. I have seen the docker-entrypoint.sh approach as well and I haven't done that here yet. I ran across another approach that did this by having the entrypoint script deduce the way to start the underlying binary depending on how it was launched, but I haven't gotten to the point of doing that quite yet.

You might take a look at the images I pushed yesterday and see if those are a bit more copacetic to your needs without the entrypoint hack, see if that helps.

@shankarinece if you can try the new images as well, see if this issue goes away for you then.

@serut
Copy link

serut commented Nov 27, 2020

I can't test, if I'm right your image v4 is for a recent Sonar, and the sonar v3 used the previous one. (a Java compatibily if I remember). So I can't test the image v4 new CMD with my existing sonar :(

@newtmitch
Copy link
Owner

Ahh, I see. I can build an image the most recent version of 3.x with a CMD-based approach if that helps?

@serut
Copy link

serut commented Nov 30, 2020

It would helps me to test it 👍

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

No branches or pull requests

3 participants