2017-09-13 1 views
0

Je suis en train d'utiliser github-pr-coverage-status-plugin, la documentation dit que je dois exécuter ce qui suit sur ma branche principale:Jenkins - Comment puis-je publier un rapport de couverture à GitHub

step([$class: 'MasterCoverageAction'])

Mais quand j'ajoute à mon pipeline I obtenir l'erreur suivante:

java.lang.UnsupportedOperationException: Can't find GIT_URL or CHANGE_URL in envs: {BRANCH_NAME=master, BUILD_DISPLAY_NAME=#41, BUILD_ID=41, BUILD_NUMBER=41, BUILD_TAG=jenkins-testci-master-41, BUILD_URL=https://jnkns-ci.myserver.com/job/testci/job/master/41/, CLASSPATH=, HUDSON_HOME=/var/jenkins_home, HUDSON_SERVER_COOKIE=01f6aedeea333d1f, HUDSON_URL=https://jnkns-ci.myserver.com/, JENKINS_HOME=/var/jenkins_home, JENKINS_SERVER_COOKIE=01f6aedeea333d1f, JENKINS_URL=https://jnkns-ci.myserver.com/, JOB_BASE_NAME=master, JOB_DISPLAY_URL=https://jnkns-ci.myserver.com/job/testci/job/master/display/redirect, JOB_NAME=testci/master, JOB_URL=https://jnkns-ci.myserver.com/job/testci/job/master/, RUN_CHANGES_DISPLAY_URL=https://jnkns-ci.myserver.com/job/testci/job/master/41/display/redirect?page=changes, RUN_DISPLAY_URL=https://jnkns-ci.myserver.com/job/testci/job/master/41/display/redirect} 
    at com.github.terma.jenkins.githubprcoveragestatus.PrIdAndUrlUtils.getGitUrl(PrIdAndUrlUtils.java:85) 
    at com.github.terma.jenkins.githubprcoveragestatus.MasterCoverageAction.perform(MasterCoverageAction.java:71) 
    at org.jenkinsci.plugins.workflow.steps.CoreStep$Execution.run(CoreStep.java:80) 
    at org.jenkinsci.plugins.workflow.steps.CoreStep$Execution.run(CoreStep.java:67) 
    at org.jenkinsci.plugins.workflow.steps.SynchronousNonBlockingStepExecution$1$1.call(SynchronousNonBlockingStepExecution.java:49) 
    at hudson.security.ACL.impersonate(ACL.java:260) 
    at org.jenkinsci.plugins.workflow.steps.SynchronousNonBlockingStepExecution$1.run(SynchronousNonBlockingStepExecution.java:46) 
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) 
    at java.util.concurrent.FutureTask.run(FutureTask.java:266) 
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) 
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) 
    at java.lang.Thread.run(Thread.java:748) 
Finished: FAILURE 

J'ai essayé plusieurs façons d'injecter ces variables. Dans mon dernier essai, j'ai même regardé le source code for this class, alors j'ai changé mon pipeline être:

pipeline { 

    agent any 

    options { 
    skipDefaultCheckout() 
    } 
    environment { 
    // calling credentials() actually sets 3 environment variables 
    // GIT_HUB with <username>:<password> 
    // GIT_HUB_USER with <username> 
    // GIT_HUB_PSW with <password> 

    GIT_HUB = credentials('tmhjenkins') 
    DOCKER_REPO = 'mobilityhouse' 
    DOCKER_HUB = credentials('tmhitadmin') 
    GIT_URL_PROPERTY = "https://[email protected]/mobilityhouse/testci.git" 
    } 

    stages{ 
    ... 
    ... 
stage('Coverage & Tests') { 
     steps { 
     sh 'pip3 install -e .' 
     sh 'make coverage-xml' 
     script { 
      currentBuild.result = 'SUCCESS' 
      sh(script: 'export GIT_URL_PROPERTY="https://[email protected]/mobilityhouse/testci.git"') 
      env.GIT_URL_PROPERTY = "https://[email protected]/mobilityhouse/testci.git" 
      step([$class: 'MasterCoverageAction']) 
     } 
     } 
    } 

... 

}

Hélas, cela échoue aussi. Alors, comment suis-je censé utiliser correctement ce plugin dans le pipeline? Toute aide serait appréciée.

Répondre

0

Après avoir battu autour du pot pendant un certain temps, j'ai décidé de jeter un regard plus profond que ce plugin Jenkins fait (un issue report in github n'a pas été Cédant beaucoup ...)

Il est apparu que les rapports de couverture principale sont stockés correctement par exemple avec la variable d'environnement correctement configuré:

step([$class: 'MasterCoverageAction', 
       scmVars: 
       [GIT_URL: 
       "https://github.com/xxx/testci.git",] 
      ]) 

Cela aurait ajouté une entrée dans le fichier journal XML dans JENKINS_HOME, comment jamais le plugin se plaignait:

Can't find master coverage repository: https://github.com/xxx/testci/pull/8 in stored: {https://github.com/myorga/testci/pull/5=0.6923, https://github.com/xxx/testci/pull/6=0.6923, https://****@github.com/myorga/testci.git=0.5385, https://github.com/xxx/testci/pull/7=0.5385} 

Cela a allumé une lumière rouge, alors j'ai creusé dans le code et j'ai trouvé le problème. Ce qui est que le PR est détecté par le plugin comme: https://github.com/xxx/testci/pull/6 cependant l'action de couverture principale aurait dû enregistrer seulement https://github.com/xxx/testci de sorte que la clé ne soit pas trouvée dans le fichier de configuration (qui est analysé par une table de hachage). Après avoir lu le code, il était assez facile de corriger le code.

Dans githubprcoveragestatus/CompareCoverageAction.java Je remplacé:

final float masterCoverage = masterCoverageRepository.get(gitUrl); 

avec les lignes suivantes à

float masterCoverage; 
if (gitUrl.contains("pull/")) { 
    final String myCorrectURL = "https://github.com/" + GitUtils.getUserRepo(gitUrl); 
    // Using masterCoverageRepository.get(myCorrectURL); is failing because URL is 
    // https://github.com/USER/REPO/pull/PR_ID 
    buildLog.println(BUILD_LOG_PREFIX + "myCorrectURL:" + myCorrectURL); 
    masterCoverage = masterCoverageRepository.get(myCorrectURL); 
} else { 
    masterCoverage = masterCoverageRepository.get(gitUrl); 
} 

Ceci a résolu mon problème, dans le bon esprit de l'open source, je fait une demande de traction à fix how a URL for Pull Request is detected, tels que d'autres puissent bénéficier de cette solution.