用java调用rpmbuild 报错,同一条命令直接复制到终端却能运行
用java调用rpmbuild 报错,同一条命令直接复制到终端却能运行。
命令如下:
rpmbuild --define "_topdir /var/lib/jenkins/workspace/compositor-build-CI/target/rpmbuild/compositor" --define "service_desc compositor" --define "service_name compositor" --define "service_release CI.last" -ba SPECS/rpmbuild.spec --clean --target i686-redhat-linux
java调用代码如下:
String rpmBuildScript = String.format("rpmbuild --define \"_topdir %s\" --define \"service_desc %s\" --define \"service_name %s\" --define \"service_release %s\" -ba SPECS/rpmbuild.spec --clean --target i686-redhat-linux", new File(privateRpmBuild).getAbsolutePath(), serviceName, serviceName, version);
getLog().info("RPM build command: " + rpmBuildScript);
Process exec = Runtime.getRuntime().exec(rpmBuildScript, null, new File(privateRpmBuild));
exec.waitFor();
BufferedReader in = new BufferedReader(new InputStreamReader(exec.getErrorStream()));
String line;
while ((line = in.readLine()) != null) {
getLog().info(line);
}
错误输出:
[INFO] RPM build command: rpmbuild --define "_topdir /var/lib/jenkins/workspace/compositor-build-CI/target/rpmbuild/compositor" --define "service_desc compositor" --define "service_name compositor" --define "service_release CI.last" -ba SPECS/rpmbuild.spec --clean --target i686-redhat-linux
[INFO] error: Macro % has illegal name (%define)
[INFO] error: Macro % has illegal name (%define)
[INFO] error: Macro % has illegal name (%define)
[INFO] error: Macro % has illegal name (%define)
[INFO] error: Macro % has illegal name (%define)
[INFO] error: Macro % has illegal name (%define)
[INFO] error: Macro % has illegal name (%define)
[INFO] error: Macro % has illegal name (%define)
[INFO] error: Macro % has illegal name (%define)
[INFO] error: failed to stat /var/lib/jenkins/workspace/compositor-build-CI/target/rpmbuild/compositor": No such file or directory
其中的"error: failed to stat /var/lib/jenkins/workspace/compositor-build-CI/target/rpmbuild/compositor": No such file or directory",这条报错语句有点诡异,我直接用Jenkins用户进去能找到这个目录,并且复制rpmbuild命令并执行能生成正确的rpm文件。
附上rpmbuild.spec文件
%define _builddir %{_topdir}/BUILD
%define _rpmdir %{_topdir}/RPMS
%define _sourcedir %{_topdir}/SOURCES
%define _specdir %{_topdir}/SPECS
%define _srcrpmdir %{_topdir}/SRPMS
%define _buildrootdir %{_topdir}/BUILDROOT
Summary: %{service_desc}
Name: %{service_name}
Version: 1.0
Release: %{service_release}
License: Restricted
Group: Applications/System
Packager: Alain
BuildRoot: %{_buildrootdir}/%{name}-%{version}_%{release}
BuildArchitectures: noarch
%description
This is a sample SPEC file for the RPM project
demonstrating how to build, package, install(deploy)
%prep
# extract the tar file containing all the sources, to the build directory.
echo service_desc = %{service_desc}
echo service_name = %{service_name}
echo service_release = %{service_release}
echo _builddir = %{_builddir}
echo _rpmdir = %{_rpmdir}
echo _sourcedir = %{_sourcedir}
echo _specdir = %{_specdir}
echo _srcrpmdir = %{_srcrpmdir}
echo _buildrootdir = %{_buildrootdir}
%build
echo "Building the project..."
%install
# This is the hierarchy which is going to be inside the package (RPM/Deb) eventually.
echo "Install phase..."
echo %{_topdir}
echo %{buildroot}
mkdir -p %{buildroot}/services/apps
mv %{_builddir}/tar_expand_temp_dir/%{name} %{buildroot}/services/apps
%post
#This runs post the install - maybe you want to execute the application already then
echo "Post install.."
echo "add service.."
cp /services/apps/%{name}/bin/%{name} /etc/init.d
chkconfig --add %{name}
echo "add service succeed"
%postun
#this runs after the uninstall
echo "Post Uninstall..."
echo "remove service"
chkconfig --del %{name}
rm /etc/init.d/%{name}
%files
# tells which files to contain in the package and with what access rights
# the triplet contains of (<file mode>, <user>, <group>). Make the necessary changes.
%defattr(-,track,track)
/*
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
悟了.