Fix: Update lf-infra-sonar macro to use JDK version
[releng/global-jjb.git] / jjb / lf-python-jobs.yaml
index 59ae549..4eb134b 100644 (file)
@@ -4,11 +4,13 @@
 ##########
 
 - builder:
-    name: lf-infra-clm-python
+    name: lf-infra-nexus-iq-python-cli
     builders:
       - inject:
-          properties-content: "CLM_PROJECT_NAME={clm-project-name}"
-      - shell: !include-raw-escape: ../shell/nexus-iq-cli.sh
+          properties-content: |
+            NEXUS_IQ_PROJECT_NAME={nexus-iq-project-name}
+            REQUIREMENTS_FILE={requirements-file}
+      - shell: !include-raw-escape: ../shell/nexus-iq-python-cli.sh
 
 - builder:
     name: lf-infra-tox-install
@@ -28,7 +30,7 @@
 # COMMON FUNCTIONS #
 ####################
 
-- lf_python_common: &lf_python_common
+- _lf_python_common: &lf_python_common
     name: lf-python-common
 
     ######################
     publishers:
       - lf-infra-publish
 
-#################
-# Python XC CLM #
-#################
+####################
+# Tox Nexus IQ CLM #
+####################
 
-- lf_python_clm_xc: &lf_python_xc_clm
-    name: lf-python-xc-clm
+- _lf_tox_nexus_iq_clm: &lf_tox_nexus_iq_clm
+    name: lf-tox-nexus-iq-clm
 
     ######################
     # Default parameters #
     ######################
 
     branch: master
-    build-days-to-keep: 30 # 30 days for troubleshooting purposes
-    build-timeout: 60
+    build-days-to-keep: 7
+    build-timeout: 15
+    cron: "@weekly"
     disable-job: false
     git-url: "$GIT_URL/$PROJECT"
     github-url: "https://github.com"
-    java-version: openjdk8
-    nexus-iq-cli-version: 1.44.0-01
+    java-version: openjdk11 # Scanner is a jar
+    nexus-iq-cli-version: 1.140.0-01
     nexus-iq-namespace: "" # Recommend a trailing dash when set. Example: odl-
-    pre-build-script: "  # pre-build script goes here"
+    nexus-target-build: "**/*"
+    pre-build-script: "# pre-build script goes here"
+    python-version: python3
+    requirements-file: requirements.txt
     stream: master
     submodule-recursive: true
     submodule-timeout: 10
     submodule-disable: false
-
-    gerrit_trigger_file_paths:
-      - compare-type: REG_EXP
-        pattern: ".*"
-
-    # github_included_regions MUST match gerrit_trigger_file_paths
-    github_included_regions:
-      - ".*"
+    tox-dir: "."
+    tox-envs: "clm"
 
     #####################
     # Job Configuration #
           project: "{project}"
           branch: "{branch}"
           stream: "{stream}"
+      - lf-infra-tox-parameters:
+          tox-dir: "{tox-dir}"
+          tox-envs: "{tox-envs}"
+      - string:
+          name: ARCHIVE_ARTIFACTS
+          default: "{archive-artifacts}"
+          description: Artifacts to archive to the logs server.
       - string:
           name: NEXUS_IQ_CLI_VERSION
           default: "{nexus-iq-cli-version}"
-          description: Nexus IQ CLI package to download and use.
+          description: Nexus IQ CLI jar to download and run.
+      - string:
+          name: NEXUS_TARGET_BUILD
+          default: "{nexus-target-build}"
+          description: File or dir to scan by Nexus CLI.
 
     wrappers:
+      - lf-infra-wrappers:
+          build-timeout: "{build-timeout}"
+          jenkins-ssh-credential: "{jenkins-ssh-credential}"
       - credentials-binding:
           - username-password-separated:
               credential-id: nexus-iq-xc-clm
-              username: CLM_USER
-              password: CLM_PASSWORD
+              username: NEXUS_IQ_USER
+              password: NEXUS_IQ_PASSWORD
+
     builders:
+      - lf-infra-pre-build
       - lf-update-java-alternatives:
           java-version: "{java-version}"
+      - lf-infra-tox-install:
+          python-version: "{python-version}"
       - shell: "{pre-build-script}"
-      - lf-infra-clm-python:
-          clm-project-name: "{nexus-iq-namespace}{project-name}"
+      - lf-infra-tox-run:
+          parallel: false
+      - lf-infra-nexus-iq-python-cli:
+          nexus-iq-project-name: "{nexus-iq-namespace}{project-name}"
+          requirements-file: "{requirements-file}"
 
 - job-template:
-    name: "{project-name}-python-clm-{stream}"
-    id: gerrit-python-xc-clm
+    name: "{project-name}-tox-nexus-iq-clm"
+    id: gerrit-tox-nexus-iq-clm
     <<: *lf_python_common
-    <<: *lf_python_xc_clm
+    <<: *lf_tox_nexus_iq_clm
 
     ######################
     # Default parameters #
     ######################
 
-    gerrit_clm_triggers:
+    gerrit_nexus_iq_triggers:
       - comment-added-contains-event:
           comment-contains-value: '^Patch Set\s+\d+:\s+run-clm\s*$'
 
     # Job Configuration #
     #####################
 
+    scm:
+      - lf-infra-gerrit-scm:
+          jenkins-ssh-credential: "{jenkins-ssh-credential}"
+          git-url: "{git-url}"
+          refspec: "$GERRIT_REFSPEC"
+          branch: "$GERRIT_BRANCH"
+          submodule-recursive: "{submodule-recursive}"
+          submodule-timeout: "{submodule-timeout}"
+          submodule-disable: "{submodule-disable}"
+          choosing-strategy: default
+
+    triggers:
+      - timed: "{obj:cron}"
+      - gerrit:
+          server-name: "{gerrit-server-name}"
+          trigger-on: "{obj:gerrit_nexus_iq_triggers}"
+          projects:
+            - project-compare-type: ANT
+              project-pattern: "{project}"
+              branches:
+                - branch-compare-type: ANT
+                  branch-pattern: "**/{branch}"
+          skip-vote:
+            successful: true
+            failed: true
+            unstable: true
+            notbuilt: true
+
+- job-template:
+    name: "{project-name}-tox-nexus-iq"
+    id: github-tox-nexus-iq-clm
+    <<: *lf_python_common
+    <<: *lf_tox_nexus_iq_clm
+
+    properties:
+      - lf-infra-properties:
+          build-days-to-keep: "{build-days-to-keep}"
+      - github:
+          url: "{github-url}/{github-org}/{project}"
+
+    scm:
+      - lf-infra-github-scm:
+          url: "{git-clone-url}{github-org}/{project}"
+          refspec: ""
+          branch: "refs/heads/{branch}"
+          submodule-recursive: "{submodule-recursive}"
+          submodule-timeout: "{submodule-timeout}"
+          submodule-disable: "{submodule-disable}"
+          choosing-strategy: default
+          jenkins-ssh-credential: "{jenkins-ssh-credential}"
+
+    triggers:
+      - timed: "{obj:cron}"
+      - github-pull-request:
+          trigger-phrase: "^run-clm$"
+          only-trigger-phrase: false
+          status-context: "CLM"
+          permit-all: true
+          github-hooks: true
+          white-list-target-branches:
+            - "{branch}"
+
+###################
+# Python Snyk CLI #
+###################
+
+- _lf_python_snyk_cli: &lf_python_snyk_cli
+    name: lf-python-snyk_cli
+
+    ######################
+    # Default parameters #
+    ######################
+
+    branch: master
+    build-days-to-keep: 30 # 30 days for troubleshooting purposes
+    build-timeout: 60
+    disable-job: false
+    git-url: "$GIT_URL/$PROJECT"
+    github-url: "https://github.com"
+    java-version: openjdk11
+    parallel: false
+    pre-build-script: "# pre-build script goes here"
+    python-version: python3
+    snyk-cli-options: ""
+    snyk-token-credential-id: snyk-token
+    snyk-org-credential-id: snyk-org
+    stream: master
+    submodule-recursive: true
+    submodule-timeout: 10
+    submodule-disable: false
+    tox-dir: "."
+    tox-envs: ""
+
+    gerrit_snyk_triggers:
+      - comment-added-contains-event:
+          comment-contains-value: '^Patch Set\s+\d+:\s+run-snyk\s*$'
+
+    parameters:
+      - lf-infra-parameters:
+          project: "{project}"
+          branch: "{branch}"
+          stream: "{stream}"
+      - string:
+          name: SNYK_CLI_OPTIONS
+          default: "{snyk-cli-options}"
+          description: Additional Snyk CLI commands and options
+      - lf-infra-tox-parameters:
+          tox-dir: "{tox-dir}"
+          tox-envs: "{tox-envs}"
+
+    wrappers:
+      - credentials-binding:
+          - text:
+              credential-id: "{snyk-token-credential-id}"
+              variable: SNYK_TOKEN
+          - text:
+              credential-id: "{snyk-org-credential-id}"
+              variable: SNYK_ORG
+
+    #####################
+    # Job Configuration #
+    #####################
+
+    disabled: "{disable-job}"
+
+    builders:
+      - lf-infra-pre-build
+      - lf-infra-tox-install:
+          python-version: "{python-version}"
+      - shell: "{pre-build-script}"
+      - lf-infra-tox-run:
+          parallel: "{parallel}"
+      - lf-infra-snyk-cli-scanner
+
+- job-template:
+    name: "{project-name}-python-snyk-cli-{stream}"
+    id: gerrit-python-snyk-cli
+    # yamllint disable-line rule:key-duplicates
+    <<: *lf_python_snyk_cli
+
     scm:
       - lf-infra-gerrit-scm:
           jenkins-ssh-credential: "{jenkins-ssh-credential}"
       - timed: "H H * * 6"
       - gerrit:
           server-name: "{gerrit-server-name}"
-          trigger-on: "{obj:gerrit_clm_triggers}"
+          trigger-on: "{obj:gerrit_snyk_triggers}"
           projects:
             - project-compare-type: ANT
               project-pattern: "{project}"
               branches:
                 - branch-compare-type: ANT
                   branch-pattern: "**/{branch}"
-              file-paths: "{obj:gerrit_trigger_file_paths}"
           skip-vote:
             successful: true
             failed: true
             notbuilt: true
 
 - job-template:
-    name: "{project-name}-python-clm-{stream}"
-    id: github-python-xc-clm
-    <<: *lf_python_common
-    <<: *lf_python_xc_clm
+    name: "{project-name}-python-snyk-cli-{stream}"
+    id: github-python-snyk-cli
+    # yamllint disable-line rule:key-duplicates
+    <<: *lf_python_snyk_cli
 
     properties:
       - lf-infra-properties:
       # Build weekly on Saturdays
       - timed: "H H * * 6"
       - github-pull-request:
-          trigger-phrase: "^run-clm$"
+          trigger-phrase: "^run-snyk$"
+          only-trigger-phrase: true
+          status-context: "SNYK scan"
+          permit-all: true
+          github-hooks: true
+          org-list:
+            - "{github-org}"
+          white-list: "{obj:github_pr_allowlist}"
+          admin-list: "{obj:github_pr_admin_list}"
+          white-list-target-branches:
+            - "{branch}"
+
+#########################
+# Python Sonar with CLI #
+#########################
+
+- _lf_cli_sonar: &lf_cli_sonar
+    name: lf-cli-sonar
+
+    ######################
+    # Default parameters #
+    ######################
+
+    branch: master # Sonar should always be run on master branch
+    build-days-to-keep: 7
+    build-timeout: 60
+    cron: "H H * * *" # run daily
+    disable-job: false
+    git-url: "$GIT_URL/$PROJECT"
+    github-url: "https://github.com"
+    # SonarCloud scan using jdk8 will become deprecated by Oct, 2020
+    # Projects not compatible with jdk11 can set java-version to something else
+    java-version: openjdk11
+    parallel: true
+    pre-build-script: "# pre-build script goes here"
+    python-version: python3
+    stream: master
+    sonar-scanner-version: "4.7.0.2747"
+    sonar-scanner-home: "$WORKSPACE/.sonar/sonar-scanner-$SONAR_SCANNER_VERSION-linux"
+    sonar-scanner-opts: "-server"
+    submodule-recursive: true
+    submodule-timeout: 10
+    submodule-disable: false
+    tox-dir: "."
+    tox-envs: ""
+
+    gerrit_trigger_file_paths:
+      - compare-type: REG_EXP
+        pattern: ".*"
+
+    # github_included_regions MUST match gerrit_trigger_file_paths
+    github_included_regions:
+      - ".*"
+
+    #####################
+    # Job Configuration #
+    #####################
+
+    disabled: "{disable-job}"
+
+    parameters:
+      - lf-infra-parameters:
+          project: "{project}"
+          branch: "{branch}"
+          stream: "{stream}"
+      - lf-infra-sonar-cli-parameters:
+          tox-dir: "{tox-dir}"
+          tox-envs: "{tox-envs}"
+          sonar-scanner-version: "{sonar-scanner-version}"
+          sonar-scanner-home: "{sonar-scanner-home}"
+          sonar-scanner-opts: "{sonar-scanner-opts}"
+      - string:
+          name: ARCHIVE_ARTIFACTS
+          default: "{archive-artifacts}"
+          description: Artifacts to archive to the logs server.
+    wrappers:
+      - credentials-binding:
+          - text:
+              credential-id: sonar-token-{project-name}
+              variable: SONAR_TOKEN
+    builders:
+      - lf-infra-pre-build
+      - lf-infra-tox-install:
+          python-version: "{python-version}"
+      - shell: "{pre-build-script}"
+      - lf-infra-tox-run:
+          parallel: "{parallel}"
+      # With Sonar CLI
+      - inject:
+          properties-content: |
+            SONARCLOUD_PROJECT_ORGANIZATION={sonarcloud-project-organization}
+            SONARCLOUD_PROJECT_KEY={sonarcloud-project-key}
+      - shell: !include-raw-escape: ../shell/sonar-cli.sh
+
+    publishers:
+      - lf-infra-publish
+
+- job-template:
+    name: "{project-name}-cli-sonar"
+    id: gerrit-cli-sonar
+    <<: *lf_python_common
+    <<: *lf_cli_sonar
+
+    ######################
+    # Default parameters #
+    ######################
+
+    gerrit_sonar_triggers:
+      - comment-added-contains-event:
+          comment-contains-value: '^Patch Set\s+\d+:\s+run-sonar\s*$'
+
+    #####################
+    # Job Configuration #
+    #####################
+
+    scm:
+      - lf-infra-gerrit-scm:
+          jenkins-ssh-credential: "{jenkins-ssh-credential}"
+          git-url: "{git-url}"
+          refspec: $GERRIT_REFSPEC
+          branch: $GERRIT_BRANCH
+          submodule-recursive: "{submodule-recursive}"
+          submodule-timeout: "{submodule-timeout}"
+          submodule-disable: "{submodule-disable}"
+          choosing-strategy: default
+
+    triggers:
+      - timed: "{obj:cron}"
+      - gerrit:
+          server-name: "{gerrit-server-name}"
+          trigger-on: "{obj:gerrit_sonar_triggers}"
+          projects:
+            - project-compare-type: "ANT"
+              project-pattern: "{project}"
+              branches:
+                - branch-compare-type: "ANT"
+                  branch-pattern: "**/{branch}"
+              file-paths: "{obj:gerrit_trigger_file_paths}"
+          skip-vote:
+            successful: true
+            failed: true
+            unstable: true
+            notbuilt: true
+
+- job-template:
+    name: "{project-name}-cli-sonar"
+    id: github-cli-sonar
+    <<: *lf_python_common
+    <<: *lf_cli_sonar
+
+    properties:
+      - lf-infra-properties:
+          build-days-to-keep: "{build-days-to-keep}"
+      - github:
+          url: "{github-url}/{github-org}/{project}"
+
+    scm:
+      - lf-infra-github-scm:
+          url: "{git-clone-url}{github-org}/{project}"
+          refspec: "+refs/pull/*:refs/remotes/origin/pr/*"
+          branch: "$sha1"
+          submodule-recursive: "{submodule-recursive}"
+          submodule-timeout: "{submodule-timeout}"
+          submodule-disable: "{submodule-disable}"
+          choosing-strategy: default
+          jenkins-ssh-credential: "{jenkins-ssh-credential}"
+
+    triggers:
+      - github-pull-request:
+          trigger-phrase: "^run-sonar$"
           only-trigger-phrase: false
-          status-context: "CLM"
+          status-context: "Python Sonar"
           permit-all: true
           github-hooks: true
           white-list-target-branches:
 # Python Sonar with Tox #
 #########################
 
-- lf_tox_sonar: &lf_tox_sonar
+- _lf_tox_sonar: &lf_tox_sonar
     name: lf-tox-sonar
 
     ######################
     disable-job: false
     git-url: "$GIT_URL/$PROJECT"
     github-url: "https://github.com"
-    java-version: openjdk8
+    java-version: openjdk11
     mvn-global-settings: global-settings
     mvn-goals: validate
     mvn-opts: ""
     mvn-params: ""
-    mvn-settings: "{mvn-settings}"
+    mvn-settings: ""
     mvn-version: mvn35
     parallel: true
     pre-build-script: "# pre-build script goes here"
     sonarcloud: false
     sonarcloud-project-key: ""
     sonarcloud-project-organization: ""
-    sonarcloud-api-token: ""
+    sonarcloud-api-token-cred-id: sonarcloud-api-token
+    sonarcloud-qualitygate-wait: false
+    # Projects not compatible with jdk17 can set java-version to something else
+    sonarcloud-java-version: openjdk17
     stream: master
     submodule-recursive: true
     submodule-timeout: 10
     submodule-disable: false
     tox-dir: "."
     tox-envs: ""
+    scan-dev-branch: false
 
     gerrit_trigger_file_paths:
       - compare-type: REG_EXP
             however to use a specific version of the sonar-maven-plugin we
             can call "org.codehaus.mojo:sonar-maven-plugin:3.3.0.603:sonar".
 
+    wrappers:
+      - credentials-binding:
+          - text:
+              credential-id: "{sonarcloud-api-token-cred-id}"
+              variable: API_TOKEN
+
     builders:
       - lf-infra-pre-build
       - lf-infra-tox-install:
                 sonarcloud-project-key: "{sonarcloud-project-key}"
                 # yamllint disable-line rule:line-length
                 sonarcloud-project-organization: "{sonarcloud-project-organization}"
-                sonarcloud-api-token: "{sonarcloud-api-token}"
+                sonarcloud-java-version: "{sonarcloud-java-version}"
+                sonarcloud-qualitygate-wait: "{sonarcloud-qualitygate-wait}"
+                scan-dev-branch: "{scan-dev-branch}"
       # With SonarQube
       - conditional-step:
           condition-kind: not
 # Tox SonarQube #
 #################
 
-- lf_tox_sonarqube: &lf_tox_sonarqube
+- _lf_tox_sonarqube: &lf_tox_sonarqube
     name: lf-tox-sonarqube
 
     ######################
     sonar-project-file: "sonar-project.properties"
     sonar-properties: ""
     sonar-task: ""
+    sonar-jdk: openjdk17
 
     #####################
     # Job Configuration #
           sonar-properties: "{sonar-properties}"
           sonar-java-opts: "{sonar-java-opts}"
           sonar-additional-args: "{sonar-additional-args}"
+          sonar-jdk: "{sonar-jdk}"
 
     publishers:
       - lf-infra-publish
     concurrent: false
     <<: *lf_tox_sonarqube
 
+    ######################
+    # Default parameters #
+    ######################
+
+    gerrit_sonar_triggers:
+      - comment-added-contains-event:
+          comment-contains-value: '^Patch Set\s+\d+:\s+run-sonar\s*$'
+
     scm:
       - lf-infra-gerrit-scm:
           branch: "$GERRIT_BRANCH"
       - timed: "{obj:cron}"
       - gerrit:
           server-name: "{gerrit-server-name}"
-          trigger-on:
-            - comment-added-contains-event:
-                comment-contains-value: '^Patch Set\s+\d+:\s+run-sonar\s*$'
+          trigger-on: "{obj:gerrit_sonar_triggers}"
           projects:
             - project-compare-type: "ANT"
               project-pattern: "{project}"
 # Tox Common #
 ##############
 
-- lf_tox_common: &lf_tox_common
+- _lf_tox_common: &lf_tox_common
     name: lf-tox-common
 
     ######################
           github-hooks: true
           org-list:
             - "{github-org}"
-          white-list: "{obj:github_pr_whitelist}"
+          white-list: "{obj:github_pr_allowlist}"
           admin-list: "{obj:github_pr_admin_list}"
           white-list-target-branches:
             - "{branch}"
 # PyPI #
 ########
 
-- lf_pypi_common: &lf_pypi_common
+- _lf_pypi_common: &lf_pypi_common
     name: lf-pypi-common
 
     ######################
     publishers:
       - lf-infra-publish
 
-- lf_pypi_verify_builders: &lf_pypi_verify_builders
+- _lf_pypi_verify_builders: &lf_pypi_verify_builders
     name: lf-pypi-verify-builders
 
     builders:
           parallel: "{parallel}"
       - shell: !include-raw-escape: ../shell/pypi-dist-build.sh
 
-- lf_pypi_merge_builders: &lf_pypi_merge_builders
-    name: lf-pypi-merge-builders
+- _lf_pypi_publish_builders: &lf_pypi_publish_builders
+    name: lf-pypi-publish-builders
 
     builders:
       - lf-infra-pre-build
     name: "{project-name}-pypi-merge-{stream}"
     id: gerrit-pypi-merge
     <<: *lf_pypi_common
-    <<: *lf_pypi_merge_builders
+    <<: *lf_pypi_publish_builders
 
-    cron: ""
+    cron: "" # avoid for pypi which rejects duplicates
     pypi-repo: pypi-test
 
     scm:
     name: "{project-name}-pypi-merge-{stream}"
     id: github-pypi-merge
     <<: *lf_pypi_common
-    <<: *lf_pypi_merge_builders
+    <<: *lf_pypi_publish_builders
 
     cron: ""
     pypi-repo: pypi-test
           github-hooks: true
           org-list:
             - "{github-org}"
-          white-list: "{obj:github_pr_whitelist}"
+          white-list: "{obj:github_pr_allowlist}"
           admin-list: "{obj:github_pr_admin_list}"
           white-list-target-branches:
             - "{branch}"
           included-regions: "{obj:github_included_regions}"
+
+- job-template:
+    name: "{project-name}-pypi-stage-{stream}"
+    id: gerrit-pypi-stage
+    <<: *lf_pypi_common
+    <<: *lf_pypi_publish_builders
+
+    cron: ""
+    pypi-repo: pypi-test
+
+    gerrit_stage_triggers:
+      - comment-added-contains-event:
+          comment-contains-value: '^Patch Set\s+\d+:\s+stage-release\s*$'
+
+    scm:
+      - lf-infra-gerrit-scm:
+          jenkins-ssh-credential: "{jenkins-ssh-credential}"
+          git-url: "{git-url}"
+          refspec: "$GERRIT_REFSPEC"
+          branch: "$GERRIT_BRANCH"
+          submodule-recursive: "{submodule-recursive}"
+          submodule-timeout: "{submodule-timeout}"
+          submodule-disable: "{submodule-disable}"
+          # stage jobs always build from tip
+          choosing-strategy: default
+
+    triggers:
+      - timed: "{obj:cron}"
+      - gerrit:
+          server-name: "{gerrit-server-name}"
+          trigger-on: "{obj:gerrit_stage_triggers}"
+          projects:
+            - project-compare-type: ANT
+              project-pattern: "{project}"
+              branches:
+                - branch-compare-type: ANT
+                  branch-pattern: "**/{branch}"
+              file-paths: "{obj:gerrit_trigger_file_paths}"
+
+- job-template:
+    name: "{project-name}-pypi-stage-{stream}"
+    id: github-pypi-stage
+    <<: *lf_pypi_common
+    <<: *lf_pypi_publish_builders
+
+    cron: ""
+    pypi-repo: pypi-test
+
+    properties:
+      - github:
+          url: "{github-url}/{github-org}/{project}"
+
+    scm:
+      - lf-infra-github-scm:
+          url: "{git-clone-url}{github-org}/{project}"
+          refspec: ""
+          branch: "refs/heads/{branch}"
+          submodule-recursive: "{submodule-recursive}"
+          submodule-timeout: "{submodule-timeout}"
+          submodule-disable: "{submodule-disable}"
+          choosing-strategy: default
+          jenkins-ssh-credential: "{jenkins-ssh-credential}"
+
+    triggers:
+      - timed: "{obj:cron}"
+      - github-pull-request:
+          trigger-phrase: "^stage-release$"
+          only-trigger-phrase: true
+          status-context: "Release"
+          permit-all: true
+          github-hooks: true
+          white-list-target-branches:
+            - "{branch}"
+          included-regions: "{obj:github_included_regions}"