Home > database >  Use python script from github on jenkins pipeline
Use python script from github on jenkins pipeline

Time:05-27

Trying to recognize how I can run the python script which is located on GitHub https://github.com/rix0rrr/cover2cover on Jenkins pipeline

In readme documentation I see 'Add the following "post step" to your Jenkins build:' and command mkdir -p target/site/cobertura && cover2cover.py target/site/jacoco/jacoco.xml src/main/java > target/site/cobertura/coverage.xml

I am not really familiar with Jenkins and python, so from my understanding before the command above

  1. I need somehow to download the script into the Jenkins workspace? Or any possibility to recognize it without downloading it?
  2. Have Jenkins tool for cloning/downloading from Github?
  3. Should I wrap this command into something like this sh mkdir folder sh python cover2cover.py

CodePudding user response:

You can set up a Jenkins pipeline with a checkout step (official docs). You should also check this blog post on how to do this. In your case it would look something like this:

dir('somedir'){
    checkout ([
        $class: 'GitSCM',
        branches:[[name: "master"]],
        doGenerateSubmoduleConfigurations: false,
        extensions: [
            [$class: 'CleanCheckout']
        ],
        submoduleCfg: [],
        userRemoteConfigs: [[
            url: 'https://github.com/rix0rrr/cover2cover.git',
            credentialsId: ''     <--- put your credentials here if necessary
        ]]
    ])
}

Since I added dir('somedir') at the top, this would get checked out into somedir, and you can then run:

mkdir -p target/site/cobertura && cover2cover.py target/site/jacoco/jacoco.xml src/main/java > target/site/cobertura/coverage.xml
  • Related