how to change sonarqube projectVersion number dynamically in jenkins












0















i tried updating sonarqube version dynamically in jenkins by adding sonar.projectVersion=${project.version} suggested at https://docs.sonarqube.org/display/SCAN/Analyzing+with+SonarQube+Scanner+for+Gradle or sonar.projectVersion=${$APP_BUILD_NUMBER} here APP_BUILD_NUMBER environmental variable but no use it considered as is version name.



Full Analysis property



# required metadata
sonar.projectKey=myproject
sonar.projectName=myproject
sonar.projectVersion=2.0.2
sonar.sourceEncoding=UTF-8


# path to source directories (required)
sonar.sources=src/main/java

# List of the module identifiers
sonar.modules=app,ui
ui.sonar.projectBaseDir=ui
# Properties can obviously be overriden for
# each module - just prefix them with the module ID
app.sonar.projectName=App

# Uncomment this line to analyse a project which is not a java project.
# The value of the property must be the key of the language.
sonar.language=java

# java version used by source files:
sonar.java.source=1.8









share|improve this question























  • can you please provide your jenkins configuration with screenshots. and elaborate if you are using a sonar-project.properties file, or if you inject other settings?

    – Simon Schrottner
    May 7 '18 at 11:08











  • You can use a shell script to change the content of a text file. You can create a variable and inject it into the sonar properties file and get it done.

    – Vighnesh Pai
    May 7 '18 at 11:21
















0















i tried updating sonarqube version dynamically in jenkins by adding sonar.projectVersion=${project.version} suggested at https://docs.sonarqube.org/display/SCAN/Analyzing+with+SonarQube+Scanner+for+Gradle or sonar.projectVersion=${$APP_BUILD_NUMBER} here APP_BUILD_NUMBER environmental variable but no use it considered as is version name.



Full Analysis property



# required metadata
sonar.projectKey=myproject
sonar.projectName=myproject
sonar.projectVersion=2.0.2
sonar.sourceEncoding=UTF-8


# path to source directories (required)
sonar.sources=src/main/java

# List of the module identifiers
sonar.modules=app,ui
ui.sonar.projectBaseDir=ui
# Properties can obviously be overriden for
# each module - just prefix them with the module ID
app.sonar.projectName=App

# Uncomment this line to analyse a project which is not a java project.
# The value of the property must be the key of the language.
sonar.language=java

# java version used by source files:
sonar.java.source=1.8









share|improve this question























  • can you please provide your jenkins configuration with screenshots. and elaborate if you are using a sonar-project.properties file, or if you inject other settings?

    – Simon Schrottner
    May 7 '18 at 11:08











  • You can use a shell script to change the content of a text file. You can create a variable and inject it into the sonar properties file and get it done.

    – Vighnesh Pai
    May 7 '18 at 11:21














0












0








0








i tried updating sonarqube version dynamically in jenkins by adding sonar.projectVersion=${project.version} suggested at https://docs.sonarqube.org/display/SCAN/Analyzing+with+SonarQube+Scanner+for+Gradle or sonar.projectVersion=${$APP_BUILD_NUMBER} here APP_BUILD_NUMBER environmental variable but no use it considered as is version name.



Full Analysis property



# required metadata
sonar.projectKey=myproject
sonar.projectName=myproject
sonar.projectVersion=2.0.2
sonar.sourceEncoding=UTF-8


# path to source directories (required)
sonar.sources=src/main/java

# List of the module identifiers
sonar.modules=app,ui
ui.sonar.projectBaseDir=ui
# Properties can obviously be overriden for
# each module - just prefix them with the module ID
app.sonar.projectName=App

# Uncomment this line to analyse a project which is not a java project.
# The value of the property must be the key of the language.
sonar.language=java

# java version used by source files:
sonar.java.source=1.8









share|improve this question














i tried updating sonarqube version dynamically in jenkins by adding sonar.projectVersion=${project.version} suggested at https://docs.sonarqube.org/display/SCAN/Analyzing+with+SonarQube+Scanner+for+Gradle or sonar.projectVersion=${$APP_BUILD_NUMBER} here APP_BUILD_NUMBER environmental variable but no use it considered as is version name.



Full Analysis property



# required metadata
sonar.projectKey=myproject
sonar.projectName=myproject
sonar.projectVersion=2.0.2
sonar.sourceEncoding=UTF-8


# path to source directories (required)
sonar.sources=src/main/java

# List of the module identifiers
sonar.modules=app,ui
ui.sonar.projectBaseDir=ui
# Properties can obviously be overriden for
# each module - just prefix them with the module ID
app.sonar.projectName=App

# Uncomment this line to analyse a project which is not a java project.
# The value of the property must be the key of the language.
sonar.language=java

# java version used by source files:
sonar.java.source=1.8






jenkins sonarqube sonarqube-scan






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked May 7 '18 at 6:55









KrishnanKrishnan

51




51













  • can you please provide your jenkins configuration with screenshots. and elaborate if you are using a sonar-project.properties file, or if you inject other settings?

    – Simon Schrottner
    May 7 '18 at 11:08











  • You can use a shell script to change the content of a text file. You can create a variable and inject it into the sonar properties file and get it done.

    – Vighnesh Pai
    May 7 '18 at 11:21



















  • can you please provide your jenkins configuration with screenshots. and elaborate if you are using a sonar-project.properties file, or if you inject other settings?

    – Simon Schrottner
    May 7 '18 at 11:08











  • You can use a shell script to change the content of a text file. You can create a variable and inject it into the sonar properties file and get it done.

    – Vighnesh Pai
    May 7 '18 at 11:21

















can you please provide your jenkins configuration with screenshots. and elaborate if you are using a sonar-project.properties file, or if you inject other settings?

– Simon Schrottner
May 7 '18 at 11:08





can you please provide your jenkins configuration with screenshots. and elaborate if you are using a sonar-project.properties file, or if you inject other settings?

– Simon Schrottner
May 7 '18 at 11:08













You can use a shell script to change the content of a text file. You can create a variable and inject it into the sonar properties file and get it done.

– Vighnesh Pai
May 7 '18 at 11:21





You can use a shell script to change the content of a text file. You can create a variable and inject it into the sonar properties file and get it done.

– Vighnesh Pai
May 7 '18 at 11:21












2 Answers
2






active

oldest

votes


















0














More detailed question would have helped to answer better. Here I made assumptions to answer better.



I assumed, dynamic version name that you are trying to update is jenkins build number. which is accessible via jenkins environment variable ${BUILD_NUMBER}. You can directly use this in "Execute Shell" (i.e) echo ${BUILD_NUMBER} will work.



You can use other environment variables too. ex: ${BUILD_TAG}. you can find the list of jenkins environment variables are available http://JENKINS-URL/env-vars.html/



These environment variables are available to your build script (i.e) ANT, Maven, Gradle, etc as well. Just make sure, you have used proper way to access environment variables inside the build script.
For Ant:



<property environment="env"/>
<property name="sonar.projectVersion" value=${env.BUILD_NUMBER}"/>





share|improve this answer































    0














    @Simon Schrottner



    We have used following in Jenkins (Note: we have used Gradle)



    sonar.projectKey=$JOB_NAME
    sonar.projectName=$JOB_NAME
    sonar.projectVersion=$BUILD_NUMBER
    sonar.exclusions=vendor/**, storage/**, resources/**
    sonar.language=java
    sonar.sources=$WORKSPACE
    sonar.sourceEncoding=UTF-8
    sonar.java.binaries=$WORKSPACE/build/classes/java/main





    share|improve this answer























      Your Answer






      StackExchange.ifUsing("editor", function () {
      StackExchange.using("externalEditor", function () {
      StackExchange.using("snippets", function () {
      StackExchange.snippets.init();
      });
      });
      }, "code-snippets");

      StackExchange.ready(function() {
      var channelOptions = {
      tags: "".split(" "),
      id: "1"
      };
      initTagRenderer("".split(" "), "".split(" "), channelOptions);

      StackExchange.using("externalEditor", function() {
      // Have to fire editor after snippets, if snippets enabled
      if (StackExchange.settings.snippets.snippetsEnabled) {
      StackExchange.using("snippets", function() {
      createEditor();
      });
      }
      else {
      createEditor();
      }
      });

      function createEditor() {
      StackExchange.prepareEditor({
      heartbeatType: 'answer',
      autoActivateHeartbeat: false,
      convertImagesToLinks: true,
      noModals: true,
      showLowRepImageUploadWarning: true,
      reputationToPostImages: 10,
      bindNavPrevention: true,
      postfix: "",
      imageUploader: {
      brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
      contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
      allowUrls: true
      },
      onDemand: true,
      discardSelector: ".discard-answer"
      ,immediatelyShowMarkdownHelp:true
      });


      }
      });














      draft saved

      draft discarded


















      StackExchange.ready(
      function () {
      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f50208602%2fhow-to-change-sonarqube-projectversion-number-dynamically-in-jenkins%23new-answer', 'question_page');
      }
      );

      Post as a guest















      Required, but never shown

























      2 Answers
      2






      active

      oldest

      votes








      2 Answers
      2






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes









      0














      More detailed question would have helped to answer better. Here I made assumptions to answer better.



      I assumed, dynamic version name that you are trying to update is jenkins build number. which is accessible via jenkins environment variable ${BUILD_NUMBER}. You can directly use this in "Execute Shell" (i.e) echo ${BUILD_NUMBER} will work.



      You can use other environment variables too. ex: ${BUILD_TAG}. you can find the list of jenkins environment variables are available http://JENKINS-URL/env-vars.html/



      These environment variables are available to your build script (i.e) ANT, Maven, Gradle, etc as well. Just make sure, you have used proper way to access environment variables inside the build script.
      For Ant:



      <property environment="env"/>
      <property name="sonar.projectVersion" value=${env.BUILD_NUMBER}"/>





      share|improve this answer




























        0














        More detailed question would have helped to answer better. Here I made assumptions to answer better.



        I assumed, dynamic version name that you are trying to update is jenkins build number. which is accessible via jenkins environment variable ${BUILD_NUMBER}. You can directly use this in "Execute Shell" (i.e) echo ${BUILD_NUMBER} will work.



        You can use other environment variables too. ex: ${BUILD_TAG}. you can find the list of jenkins environment variables are available http://JENKINS-URL/env-vars.html/



        These environment variables are available to your build script (i.e) ANT, Maven, Gradle, etc as well. Just make sure, you have used proper way to access environment variables inside the build script.
        For Ant:



        <property environment="env"/>
        <property name="sonar.projectVersion" value=${env.BUILD_NUMBER}"/>





        share|improve this answer


























          0












          0








          0







          More detailed question would have helped to answer better. Here I made assumptions to answer better.



          I assumed, dynamic version name that you are trying to update is jenkins build number. which is accessible via jenkins environment variable ${BUILD_NUMBER}. You can directly use this in "Execute Shell" (i.e) echo ${BUILD_NUMBER} will work.



          You can use other environment variables too. ex: ${BUILD_TAG}. you can find the list of jenkins environment variables are available http://JENKINS-URL/env-vars.html/



          These environment variables are available to your build script (i.e) ANT, Maven, Gradle, etc as well. Just make sure, you have used proper way to access environment variables inside the build script.
          For Ant:



          <property environment="env"/>
          <property name="sonar.projectVersion" value=${env.BUILD_NUMBER}"/>





          share|improve this answer













          More detailed question would have helped to answer better. Here I made assumptions to answer better.



          I assumed, dynamic version name that you are trying to update is jenkins build number. which is accessible via jenkins environment variable ${BUILD_NUMBER}. You can directly use this in "Execute Shell" (i.e) echo ${BUILD_NUMBER} will work.



          You can use other environment variables too. ex: ${BUILD_TAG}. you can find the list of jenkins environment variables are available http://JENKINS-URL/env-vars.html/



          These environment variables are available to your build script (i.e) ANT, Maven, Gradle, etc as well. Just make sure, you have used proper way to access environment variables inside the build script.
          For Ant:



          <property environment="env"/>
          <property name="sonar.projectVersion" value=${env.BUILD_NUMBER}"/>






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered May 7 '18 at 12:06









          FidelFidel

          6821511




          6821511

























              0














              @Simon Schrottner



              We have used following in Jenkins (Note: we have used Gradle)



              sonar.projectKey=$JOB_NAME
              sonar.projectName=$JOB_NAME
              sonar.projectVersion=$BUILD_NUMBER
              sonar.exclusions=vendor/**, storage/**, resources/**
              sonar.language=java
              sonar.sources=$WORKSPACE
              sonar.sourceEncoding=UTF-8
              sonar.java.binaries=$WORKSPACE/build/classes/java/main





              share|improve this answer




























                0














                @Simon Schrottner



                We have used following in Jenkins (Note: we have used Gradle)



                sonar.projectKey=$JOB_NAME
                sonar.projectName=$JOB_NAME
                sonar.projectVersion=$BUILD_NUMBER
                sonar.exclusions=vendor/**, storage/**, resources/**
                sonar.language=java
                sonar.sources=$WORKSPACE
                sonar.sourceEncoding=UTF-8
                sonar.java.binaries=$WORKSPACE/build/classes/java/main





                share|improve this answer


























                  0












                  0








                  0







                  @Simon Schrottner



                  We have used following in Jenkins (Note: we have used Gradle)



                  sonar.projectKey=$JOB_NAME
                  sonar.projectName=$JOB_NAME
                  sonar.projectVersion=$BUILD_NUMBER
                  sonar.exclusions=vendor/**, storage/**, resources/**
                  sonar.language=java
                  sonar.sources=$WORKSPACE
                  sonar.sourceEncoding=UTF-8
                  sonar.java.binaries=$WORKSPACE/build/classes/java/main





                  share|improve this answer













                  @Simon Schrottner



                  We have used following in Jenkins (Note: we have used Gradle)



                  sonar.projectKey=$JOB_NAME
                  sonar.projectName=$JOB_NAME
                  sonar.projectVersion=$BUILD_NUMBER
                  sonar.exclusions=vendor/**, storage/**, resources/**
                  sonar.language=java
                  sonar.sources=$WORKSPACE
                  sonar.sourceEncoding=UTF-8
                  sonar.java.binaries=$WORKSPACE/build/classes/java/main






                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Jan 2 at 9:14









                  Mahendra KoratMahendra Korat

                  3118




                  3118






























                      draft saved

                      draft discarded




















































                      Thanks for contributing an answer to Stack Overflow!


                      • Please be sure to answer the question. Provide details and share your research!

                      But avoid



                      • Asking for help, clarification, or responding to other answers.

                      • Making statements based on opinion; back them up with references or personal experience.


                      To learn more, see our tips on writing great answers.




                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function () {
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f50208602%2fhow-to-change-sonarqube-projectversion-number-dynamically-in-jenkins%23new-answer', 'question_page');
                      }
                      );

                      Post as a guest















                      Required, but never shown





















































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown

































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown







                      Popular posts from this blog

                      Monofisismo

                      Angular Downloading a file using contenturl with Basic Authentication

                      Olmecas