我正在尝试使用 Jenkins 将 Sonar 任务集成到 Ant 构建中。SonarQube服务器在默认端口成功运行。SonarQube 网页界面已成功打开。
问题是当我使用 Jenkins 从 Ant 构建文件运行声纳任务时,它给出错误 java.lang.IllegalStateException:批处理未启动。无法执行任务
声纳任务 ANt build Jenkins 控制台输出定义如下:
Console Output
Started by user Pradeep Podishetty
Building in workspace /var/lib/jenkins/workspace/salesforce-code-analysis
[WS-CLEANUP] Deleting project workspace...
[WS-CLEANUP] Done
Buildfile: /var/lib/jenkins/workspace/salesforce-code-analysis/build.xml
deletesrc:
-check-package-xml:
-create-default-package-xml:
download:
[codescan] Manifest file: /var/lib/jenkins/workspace/salesforce-code-analysis/petra/src/package.xml
[codescan] Retrieving results with API Version 40.0...
[codescan] ...in progress (waiting for 2000ms)
[codescan] ...in progress (waiting for 4000ms)
[codescan] ...in progress (waiting for 8000ms)
[codescan] ...in progress (waiting for 16000ms)
[codescan] Retrieve warnings:
[codescan] unpackaged/package.xml - Metadata API received improper input. Please ensure file name and capitalization is correct. Load of metadata from db failed for metadata of type:AppMenu and file name:AppSwitcher.
[codescan]
[codescan] Writing files to disk
BUILD SUCCESSFUL
Total time: 18 seconds
[salesforce-code-analysis] $ /var/lib/jenkins/tools/hudson.tasks.Ant_AntInstallation/default/bin/ant -Dsonar.projectKey=Test -Dsonar.projectName=GIT-Test-Dev -Dsalesforce.url=https://test.salesforce.com/ -Dsalesforce.username=*************** -Dsonar.host.url=https://static.itx-tools.net -Dsonar.projectVersion=1.0.0-SNAPSHOT ******** -Duser.dir=petra sonar
Buildfile: /var/lib/jenkins/workspace/salesforce-code-analysis/build.xml
sonar:
[sonar:sonar] Apache Ant(TM) version 1.10.1 compiled on February 2 2017
[sonar:sonar] SonarQube Ant Task version: 2.5
[sonar:sonar] Loaded from: file:/var/lib/jenkins/workspace/sonarqube-ant-task-2.5.jar
[sonar:sonar] User cache: /var/lib/jenkins/.sonar/cache
[sonar:sonar] Load global repositories
BUILD FAILED
/var/lib/jenkins/workspace/salesforce-code-analysis/build.xml:63: java.lang.IllegalStateException: Batch is not started. Unable to execute task.
at org.sonar.batch.bootstrapper.Batch.checkStarted(Batch.java:139)
at org.sonar.batch.bootstrapper.Batch.doStop(Batch.java:175)
at org.sonar.batch.bootstrapper.Batch.stop(Batch.java:171)
at org.sonarsource.scanner.api.internal.batch.BatchIsolatedLauncher.stop(BatchIsolatedLauncher.java:57)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.sonarsource.scanner.api.internal.IsolatedLauncherProxy.invoke(IsolatedLauncherProxy.java:60)
at com.sun.proxy.$Proxy0.stop(Unknown Source)
at org.sonarsource.scanner.api.EmbeddedScanner.doStop(EmbeddedScanner.java:226)
at org.sonarsource.scanner.api.EmbeddedScanner.stop(EmbeddedScanner.java:165)
at org.sonarsource.scanner.ant.SonarQubeTask.launchAnalysis(SonarQubeTask.java:101)
at org.sonarsource.scanner.ant.SonarQubeTask.execute(SonarQubeTask.java:81)
at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:293)
at sun.reflect.GeneratedMethodAccessor4.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
at org.apache.tools.ant.Task.perform(Task.java:348)
at org.apache.tools.ant.Target.execute(Target.java:435)
at org.apache.tools.ant.Target.performTasks(Target.java:456)
at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1405)
at org.apache.tools.ant.Project.executeTarget(Project.java:1376)
at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41)
at org.apache.tools.ant.Project.executeTargets(Project.java:1260)
at org.apache.tools.ant.Main.runBuild(Main.java:857)
at org.apache.tools.ant.Main.startAnt(Main.java:236)
at org.apache.tools.ant.launch.Launcher.run(Launcher.java:287)
at org.apache.tools.ant.launch.Launcher.main(Launcher.java:113)
Total time: 2 seconds
Build step 'Invoke Ant' marked build as failure
Finished: FAILURE
我的构建.xml如下所示:
<project name="VillageChief DataHub" xmlns:sf="salesforce">
<!-- Pick up per-project folder settings-->
<property file="${user.dir}/sonar-project.properties"/>
<!-- put global settings in here -->
<property file="${basedir}/antbuild.properties"/>
<!-- proxy settings -->
<property name="http.proxyHost" value="" />
<property name="http.proxyPort" value="0" />
<property name="http.proxyUser" value="" />
<property name="http.proxyPassword" value="" />
<property name="http.nonProxyHosts" value="localhost|*.local|127.*|[::1]" />
<!--if ntlm is used -->
<!--<property name="http.auth.ntlm.domain" value="" />-->
<!-- tell ant about proxy -->
<setproxy proxyhost="${http.proxyHost}" proxyport="${http.proxyPort}"
proxyuser="${http.proxyUser}" proxypassword="${http.proxyPassword}"
nonproxyhosts="${http.nonProxyHosts}"/>
<!-- some tasks in codescan need https equivalents -->
<property name="https.proxyHost" value="${http.proxyHost}" />
<property name="https.proxyPort" value="${http.proxyPort}" />
<property name="https.proxyUser" value="${http.proxyUser}" />
<property name="https.proxyPassword" value="${http.proxyPassword}" />
<!-- define if not already defined properties -->
<property name="salesforce.url" value="https://www.salesforce.com" />
<!-- Define the ant tasks. Use ant.file.dir to ensure we look for the jar files next to antbuild.xml -->
<dirname file="${ant.file}" property="ant.file.dir" />
<taskdef uri="antlib:org.sonar.ant" resource="org/sonar/ant/antlib.xml">
<classpath path="${ant.file.dir}/../sonarqube-ant-task-2.5.jar" />
</taskdef>
<taskdef name='codescan' classname='com.villagechief.codescan.versions.ant.ScmCommitterTask'>
<classpath path="${ant.file.dir}/../force-versions-1.4.jar" />
</taskdef>
<!-- Add the target -->
<target name="sonar">
<!-- Please see https://docs.sonarqube.org/display/SONAR/Analysis+Parameters for details on parameters to pass to SonarQube -->
<!-- location properties -->
<property name="sonar.projectBaseDir" value="${user.dir}" />
<!-- define if not already defined properties -->
<property name="salesforce.url" value="https://www.salesforce.com" />
<property name="sonar.projectVersion" value="1.0-SNAPSHOT" />
<property name="sonar.sources" value="${user.dir}/src" />
<property name="sonar.sourceEncoding" value="utf8" />
<property name="sonar.host.url" value="http://localhost:9000" />
<!-- If the Anyone group is not granted Execute Analysis permission or if the SonarQube instance
is secured (the sonar.forceAuthentication property is setto true), the credentials of a us er
having been granted Execute Analysis permission have to be provided through the sonar.login
and sonar.password properties
-->
<!-- <property name="sonar.login" value="USER" /> -->
<!-- <property name="sonar.password" value="PASS" /> -->
<sonar:sonar xmlns:sonar="antlib:org.sonar.ant" />
</target>
<target name="deletesrc">
<delete dir="${user.dir}/src">
<include name="**/*"/>
<exclude name="package.xml"/>
</delete>
</target>
<target name="commit">
<codescan username="${salesforce.username}" password="${salesforce.password}" serverurl="${salesforce.url}" writeFiles="true" repository="${scm}" packageXmlPath="${user.dir}/src/package.xml" outputPath="${user.dir}/src">
<fileset dir="${user.dir}/src">
<include name="**/*"/>
</fileset>
</codescan>
</target>
<target name="-check-package-xml">
<available property="package.xml.exists" file="${user.dir}/src/package.xml"></available>
</target>
<target name="-create-default-package-xml" depends="-check-package-xml" unless="package.xml.exists">
<copy file="${ant.file.dir}/default.package.xml" tofile="${user.dir}/src/package.xml" />
</target>
<target name="download" depends="-create-default-package-xml">
<codescan username="${salesforce.username}" password="${salesforce.password}" serverurl="${salesforce.url}" writeFiles="true" packageXmlPath="${user.dir}/src/package.xml" outputPath="${user.dir}/src">
<fileset dir="${user.dir}/src">
<include name="**/*"/>
</fileset>
</codescan>
</target>
<target name="downloadAndCommit" depends="-create-default-package-xml">
<codescan username="${salesforce.username}" password="${salesforce.password}" serverurl="${salesforce.url}" writeFiles="true" repository="${scm}" packageXmlPath="${user.dir}/src/package.xml" outputPath="${user.dir}/src">
<fileset dir="${user.dir}/src">
<include name="**/*"/>
</fileset>
</codescan>
</target>
<target name="deploy">
<!-- Retrieve the contents listed in the file codepkg/package.xml into the codepkg directory -->
<sf:deploy username="${salesforce.username}" password="${salesforce.password}" serverurl="${salesforce.url}"
deployroot="src"/>
</target>
<target name="commitall">
<exec executable="git" dir="${user.dir}">
<arg value="add"/>
<arg value="-A"/>
</exec>
<exec executable="git" dir="${user.dir}">
<arg value="commit"/>
<arg value="-a"/>
<arg value="-m"/>
<arg value="<automcommit: all>"/>
</exec>
</target>
<!-- <target name="analyse" depends="deletesrc, download, commit, commitall, sonar" /> -->
<target name="analyse" depends="deletesrc, download, sonar" />
<target name="analyze" depends="deletesrc, download, sonar" />
</project>
您的配置中应该存在问题,导致对全局存储库 WS 的调用失败(您可以使用属性sonar.verbose=true
启用详细输出以获取更多详细信息(。
由于一个错误,堆栈跟踪不是很有帮助: https://jira.sonarsource.com/browse/ANTTASK-56
我通过在build.xml中添加"sonar.login"和"sonar.password"属性来解决它。
参考声纳扫描仪引擎未启动