Jenkins管道上的动态参数取决于分支

时间:2018-06-20 08:13:42

标签: jenkins jenkins-pipeline

我的詹金斯管道上有这样的东西

[AddINotifyPropertyChangedInterface]
public abstract class ViewModelBase
{
    protected readonly MainController mainController;
    protected static readonly log4net.ILog log = LogHelper.GetLogger();

    protected readonly Window window;

    public ICommand CloseWindowCommand { get; }

    protected ViewModelBase(Window window)
    {
        mainController = MainController.GetInstance();
        this.window = window;

        CloseWindowCommand = new RelayCommand(CloseWindow);

        Initialize();
    }

    protected void CloseWindow()
    {
        window.Close();
    }

    protected bool? ShowDialog(Window windowToOpen)
    {
        windowToOpen.Owner = window;
        return windowToOpen.ShowDialog();
    }

    private void Initialize()
    {
        window.WindowStartupLocation = WindowStartupLocation.CenterOwner;
        window.DataContext = this;
    }

    protected void DisplayAlertAndLogError(string message, Exception ex)
    {
        log.Error(message, ex);
        MessageBox.Show(message, "Fehler", MessageBoxButton.OK, MessageBoxImage.Error);
    }
}

很明显,如果管道在master分支上运行,则第一个没有意义的参数。因此,仅当管道不在master分支上运行时,才如何拥有此参数?

1 个答案:

答案 0 :(得分:2)

如果还没有找到方法,可以像这样有条件地将元素添加到参数列表中

def list = []
if (env.BRANCH_NAME != 'master') {
    list.add(booleanParam(description: 'Merge master to this branch', name: 'merge_master', defaultValue: false))
}
//example list.add(otherParams)
//finally
properties([parameters(list)])

有关adding to lists in groovy can be found here的更多信息。