如何在Jenkins Multibranch Pipeline插件中从pom获取artifactId和版本

时间:2016-04-22 12:08:27

标签: java maven jenkins jenkins-plugins jenkins-pipeline

我已经使用Multibranch Pipeline插件设置了Jenkins,并且我已将其配置为在GitHub存储库中存在提交时触发构建。我想将由maven构建创建的.jar文件复制到自定义目录。为此,我必须指定文件的名称。问题是文件的名称包含artifactId和pom.xml文件中的版本。版本经常发生变化。

有没有办法从pom.xml文件中获取Jenkins中的artifactId和版本?我有红色this blog post,但它说只有在Jenkins中创建一个Maven项目时,这些Jenkins变量才有效。

1 个答案:

答案 0 :(得分:2)

你可以这样做:

    public Bitmap takeScreenshot() {
    View rootView = findViewById(android.R.id.content).getRootView();
    rootView.setDrawingCacheEnabled(true);
    return rootView.getDrawingCache();
    }

    public void saveBitmap(Bitmap bitmap) {
    File imagePath = new File(Environment.getExternalStorageDirectory() + "/screenshot.png");
    FileOutputStream fos;
    try {
        fos = new FileOutputStream(imagePath);
        bitmap.compress(Bitmap.CompressFormat.PNG, 100, fos);
        fos.flush();
        fos.close();
    } catch (FileNotFoundException e) {
        Log.e("GREC", e.getMessage(), e);
    } catch (IOException e) {
        Log.e("GREC", e.getMessage(), e);
    }
   }

您需要Pipeline Utility Steps plugin才能实现此目的。