Praqma / JenkinsAsCodeReference

This repository is intended for the reference Jenkins configuration as code as well as JobDSL library
BSD 3-Clause "New" or "Revised" License
142 stars 110 forks source link

Gradle doesn't use proxies in jenkins-as-a-code-pipeline #206

Closed robinerd closed 6 years ago

robinerd commented 6 years ago

The gradlew commands in "Verify JobDSL" stage fails to fetch plugins behind our corporate firewall since it doesn't use the proxy.

I was able to make it work by passing the proxies as -D parameters to gradlew Here's what I did, feel free to add it or modify it as you like.

stage('Verify JobDSL') {
       proxyHTTP = ""
       if(env.http_proxy) {
         def tokens = env.http_proxy.replace("http://", "").replace("https://", "").split(':')
         def host = tokens[0]
         def port = tokens[1]
         proxyHTTP = "-Dhttp.proxyHost=${host} -Dhttp.proxyPort=${port}"
       }

       proxyHTTPS = ""
       if(env.https_proxy) {
         def tokens = env.https_proxy.replace("http://", "").replace("https://", "").split(':')
         def host = tokens[0]
         def port = tokens[1]
         proxyHTTPS = "-Dhttps.proxyHost=${host} -Dhttps.proxyPort=${port}"
       }

       sh "cd jobdsl-gradle && ./gradlew ${proxyHTTP} ${proxyHTTPS} buildXml"
       sh "cd jobdsl-gradle && ./gradlew ${proxyHTTP} ${proxyHTTPS} test"
   }