lasote / skynet_example

11 stars 13 forks source link

Does not work when running inside docker container #2

Open bilke opened 7 years ago

bilke commented 7 years ago

I have read the blog post on Jenkins and my SimpleBuild script looks like this:

properties([parameters([string(description: 'Build label', name: 'build_label', defaultValue: 'Unamed'),
                        string(description: 'Channel', name: 'channel', defaultValue: 'stable'),
                        string(description: 'Name/Version', name: 'name_version', defaultValue: 'zlib/1.2.8'),
                        string(description: 'Profile', name: 'profile', defaultValue: './profiles/osx_64'),
                        string(description: 'Config repository branch', name: 'conf_repo_branch', defaultValue: 'master'),
                        string(description: 'Config repository url', name: 'conf_repo_url', defaultValue: 'https://github.com/bilke/conf_jenkins_test.git'),
                       ])])

node('docker') {
    //currentBuild.displayName = params.build_label
    def data
    def conf_repo_dir
    def client
    def serverName
    def image = docker.image('ogs6/gcc-conan')
    image.pull()
    image.inside() {
        stage("Cleanup") {
                    dir("./.conan") {
                        deleteDir()
                    }
                }
        stage("Configure/Get repositories"){
            dir("_conf_repo"){
                git branch: params.conf_repo_branch, url: params.conf_repo_url
                data = readYaml file: "conan_ci_conf.yml"
                conf_repo_dir = pwd()
            }
            def server = Artifactory.server data.artifactory.name
            client = Artifactory.newConanClient userHome: pwd()
            serverName = client.remote.add server: server, repo: data.artifactory.repo
            //client.run(command: "remote remove conan.io")

            dir("_lib_repo"){
                git branch: data.repos[params.name_version].branch, url: data.repos[params.name_version].url
            }
        }
        stage("Build packages"){
            // For each profile
            dir("_lib_repo"){
                dir(data.repos[params.name_version].dir){
                    client.run(command: "test_package --update --profile \"" + conf_repo_dir + "/" + params.profile + "\"")
                }
            }
        }

        stage("Upload Artifactory"){
            String command = "upload * -r ${serverName} --all -c"
            client.run(command: command)
        }
    }
}

I wrapped everything to run inside a docker container. The problem is that dir() does not work inside a docker container and therefore client.run(command: "test_package ... does not have the correct working directory. I know this is a serious limitation of the docker plugin but do you have any ideas how to workaround that?

Using the Artifactory Conan client in combination with Docker would be really helpful to build Conan packages for different compiler (similar to the Travis CI workflow).

Another option maybe would be to use just plain sh 'conan ...'-commands inside the container and upload to Artifactory from outside the docker container...

lasote commented 7 years ago

Hi, thanks for trying it. Honestly, I've not tried it with Docker, I'm a pretty newbie with Jenkins and PipeLine. In 0.25 (will be released next week) we introduced the "--cwd" parameter to the 'test_package' command, so could help with this. It allows to specify the current directory, so instead of change dir with Jenkins, we can do it with that. Please, stay tuned and tell us if you have any problem.

madpipeline commented 6 years ago

I've hit a similar issue. The fix is: to NOT SET CONAN_USER_HOME either with the env variable or by passing it to newConanClient(). It breaks something in the Artifactory plugin.

madpipeline commented 6 years ago

I've also reported this issue here: https://issues.jenkins-ci.org/browse/JENKINS-50218