summaryrefslogtreecommitdiffstats
path: root/jenkins_jobs/modules/builders.py
blob: e26f98bb12beb545f920ee4c2587ed7c74b5d487 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
3615
3616
3617
3618
3619
3620
3621
3622
3623
3624
3625
3626
3627
3628
3629
3630
3631
3632
3633
3634
3635
3636
3637
3638
3639
3640
3641
3642
3643
3644
3645
3646
3647
3648
3649
3650
3651
3652
3653
3654
3655
3656
3657
3658
3659
3660
3661
3662
3663
3664
3665
3666
3667
3668
3669
3670
3671
3672
3673
3674
3675
3676
3677
3678
3679
3680
3681
3682
3683
3684
3685
3686
3687
3688
3689
3690
3691
3692
3693
3694
3695
3696
3697
3698
3699
3700
3701
3702
3703
3704
3705
3706
3707
3708
3709
3710
3711
3712
3713
3714
3715
3716
3717
3718
3719
3720
3721
3722
3723
3724
3725
3726
3727
3728
3729
3730
3731
3732
3733
3734
3735
3736
3737
3738
3739
3740
3741
3742
3743
3744
3745
3746
3747
3748
3749
3750
3751
3752
3753
3754
3755
3756
3757
3758
3759
3760
3761
3762
3763
3764
3765
3766
3767
3768
3769
3770
3771
3772
3773
3774
3775
3776
3777
3778
3779
3780
3781
3782
3783
3784
3785
3786
3787
3788
3789
3790
3791
3792
3793
3794
3795
3796
3797
3798
3799
3800
3801
3802
3803
3804
3805
3806
3807
3808
3809
3810
3811
3812
3813
3814
3815
3816
3817
3818
3819
3820
3821
3822
3823
3824
3825
3826
3827
3828
3829
3830
3831
3832
3833
3834
3835
3836
3837
3838
3839
3840
3841
3842
3843
3844
3845
3846
3847
3848
3849
3850
3851
3852
3853
3854
3855
3856
3857
3858
3859
3860
3861
3862
3863
3864
3865
3866
3867
3868
3869
3870
3871
3872
3873
3874
3875
3876
3877
3878
3879
3880
3881
3882
3883
3884
3885
3886
3887
3888
3889
3890
3891
3892
3893
3894
3895
3896
3897
3898
3899
3900
3901
3902
3903
3904
3905
3906
3907
3908
3909
3910
3911
3912
3913
3914
3915
3916
3917
3918
3919
3920
3921
3922
3923
3924
3925
3926
3927
3928
3929
3930
3931
3932
3933
3934
3935
3936
3937
3938
3939
3940
3941
3942
3943
3944
3945
3946
3947
3948
3949
3950
3951
3952
3953
3954
3955
3956
3957
3958
3959
3960
3961
3962
3963
3964
3965
3966
3967
3968
3969
3970
3971
3972
3973
3974
3975
3976
3977
3978
3979
3980
3981
3982
3983
3984
3985
3986
3987
3988
3989
3990
3991
3992
3993
3994
3995
3996
3997
3998
3999
4000
4001
4002
4003
4004
4005
4006
4007
4008
4009
4010
4011
4012
4013
4014
4015
4016
4017
4018
4019
4020
4021
4022
4023
4024
4025
4026
4027
4028
4029
4030
4031
4032
4033
4034
4035
4036
4037
4038
4039
4040
4041
4042
4043
4044
4045
4046
4047
4048
4049
4050
4051
4052
4053
4054
4055
4056
4057
4058
4059
4060
4061
4062
4063
4064
4065
4066
4067
4068
4069
4070
4071
4072
4073
4074
4075
4076
4077
4078
4079
4080
4081
4082
4083
4084
4085
4086
4087
4088
4089
4090
4091
4092
4093
4094
4095
4096
4097
4098
4099
4100
4101
4102
4103
4104
4105
4106
4107
4108
4109
4110
4111
4112
4113
4114
4115
4116
4117
4118
4119
4120
4121
4122
4123
4124
4125
4126
4127
4128
4129
4130
4131
4132
4133
4134
4135
4136
4137
4138
4139
4140
4141
4142
4143
4144
4145
4146
4147
4148
4149
4150
4151
4152
4153
4154
4155
4156
4157
4158
4159
4160
4161
4162
4163
4164
4165
4166
4167
4168
4169
4170
4171
4172
4173
4174
4175
4176
4177
4178
4179
4180
4181
4182
4183
4184
4185
4186
4187
4188
4189
4190
4191
4192
4193
4194
4195
4196
4197
4198
4199
4200
4201
4202
4203
4204
4205
4206
4207
4208
4209
4210
4211
4212
4213
4214
4215
4216
4217
4218
4219
4220
4221
4222
4223
4224
4225
4226
4227
4228
4229
4230
4231
4232
4233
4234
4235
4236
4237
4238
4239
4240
4241
4242
4243
4244
4245
4246
4247
4248
4249
4250
4251
4252
4253
4254
4255
4256
4257
4258
4259
4260
4261
4262
4263
4264
4265
4266
4267
4268
4269
4270
4271
4272
4273
4274
4275
4276
4277
4278
4279
4280
4281
4282
4283
4284
4285
4286
4287
4288
4289
4290
4291
4292
4293
4294
4295
4296
4297
4298
4299
4300
4301
4302
4303
4304
4305
4306
4307
4308
4309
4310
4311
4312
4313
4314
4315
4316
4317
4318
4319
4320
4321
4322
4323
4324
4325
4326
4327
4328
4329
4330
4331
4332
4333
4334
4335
4336
4337
4338
4339
4340
4341
4342
4343
4344
4345
4346
4347
4348
4349
4350
4351
4352
4353
4354
4355
4356
4357
4358
4359
4360
4361
4362
4363
4364
4365
4366
4367
4368
4369
4370
4371
4372
4373
4374
4375
4376
4377
4378
4379
4380
4381
4382
4383
4384
4385
4386
4387
4388
4389
4390
4391
4392
4393
4394
4395
4396
4397
4398
4399
4400
4401
4402
4403
4404
4405
4406
4407
4408
4409
4410
4411
4412
4413
4414
4415
4416
4417
4418
4419
4420
4421
4422
4423
4424
4425
4426
4427
4428
4429
4430
4431
4432
4433
4434
4435
4436
4437
4438
4439
4440
4441
4442
4443
4444
4445
4446
4447
4448
4449
4450
4451
4452
4453
4454
4455
4456
4457
4458
4459
4460
4461
4462
4463
4464
4465
4466
4467
4468
4469
4470
4471
4472
4473
4474
4475
4476
4477
4478
4479
4480
4481
4482
4483
4484
4485
4486
4487
4488
4489
4490
4491
4492
4493
4494
4495
4496
4497
4498
4499
4500
4501
4502
4503
4504
4505
4506
4507
4508
4509
4510
4511
4512
4513
4514
4515
4516
4517
4518
4519
4520
4521
4522
4523
4524
4525
4526
4527
4528
4529
4530
4531
4532
4533
4534
4535
4536
4537
4538
4539
4540
4541
4542
4543
4544
4545
4546
4547
4548
4549
4550
4551
4552
4553
4554
4555
4556
4557
4558
4559
4560
4561
4562
4563
4564
4565
4566
4567
4568
4569
4570
4571
4572
4573
4574
4575
4576
4577
4578
4579
4580
4581
4582
4583
4584
4585
4586
4587
4588
4589
4590
4591
4592
4593
4594
4595
4596
4597
4598
4599
4600
4601
4602
4603
4604
4605
4606
4607
4608
4609
4610
4611
4612
4613
4614
4615
4616
4617
4618
4619
4620
4621
4622
4623
4624
4625
4626
4627
4628
4629
4630
4631
4632
4633
4634
4635
4636
4637
4638
4639
4640
4641
4642
4643
4644
4645
4646
4647
4648
4649
4650
4651
4652
4653
4654
4655
4656
4657
4658
4659
4660
4661
4662
4663
4664
4665
4666
4667
4668
4669
4670
4671
4672
4673
4674
4675
4676
4677
4678
4679
4680
4681
4682
4683
4684
4685
4686
4687
4688
4689
4690
4691
4692
4693
4694
4695
4696
4697
4698
4699
4700
4701
4702
4703
4704
4705
4706
4707
4708
4709
4710
4711
4712
4713
4714
4715
4716
4717
4718
4719
4720
4721
4722
4723
4724
4725
4726
4727
4728
4729
4730
4731
4732
4733
4734
4735
4736
4737
4738
4739
4740
4741
4742
4743
4744
4745
4746
4747
4748
4749
4750
4751
4752
4753
4754
4755
4756
4757
# Copyright 2012 Hewlett-Packard Development Company, L.P.
# Copyright 2012 Varnish Software AS
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.


"""
Builders define actions that the Jenkins job should execute.  Examples
include shell scripts or maven targets.  The ``builders`` attribute in
the :ref:`Job` definition accepts a list of builders to invoke.  They
may be components defined below, locally defined macros (using the top
level definition of ``builder:``, or locally defined components found
via the ``jenkins_jobs.builders`` entry point.

**Component**: builders
  :Macro: builder
  :Entry Point: jenkins_jobs.builders

Example::

  job:
    name: test_job

    builders:
      - shell: "make test"

"""

import logging
import sys
import xml.etree.ElementTree as XML

import six

from jenkins_jobs.errors import is_sequence
from jenkins_jobs.errors import InvalidAttributeError
from jenkins_jobs.errors import JenkinsJobsException
from jenkins_jobs.errors import MissingAttributeError
import jenkins_jobs.modules.base
import jenkins_jobs.modules.helpers as helpers
import pkg_resources
from jenkins_jobs.modules import hudson_model
from jenkins_jobs.modules.publishers import ssh
from jenkins_jobs.modules.publishers import cifs

logger = logging.getLogger(__name__)


def shell(registry, xml_parent, data):
    """yaml: shell
    Execute a shell command.

    There are two ways of configuring the builder, with a plain string to
    execute:

    :arg str parameter: the shell command to execute

    Or with a mapping that allows other parameters to be passed:

    :arg str command: the shell command to execute
    :arg int unstable-return:
        the shell exit code to interpret as an unstable build result

    Example:

    .. literalinclude:: /../../tests/builders/fixtures/shell.yaml
       :language: yaml

    .. literalinclude::
        /../../tests/builders/fixtures/shell-unstable-return.yaml
       :language: yaml
    """
    shell = XML.SubElement(xml_parent, "hudson.tasks.Shell")
    if isinstance(data, six.string_types):
        XML.SubElement(shell, "command").text = data
    else:
        mappings = [
            ("command", "command", None),
            ("unstable-return", "unstableReturn", 0),
        ]
        helpers.convert_mapping_to_xml(shell, data, mappings, fail_required=True)


def python(registry, xml_parent, data):
    """yaml: python
    Execute a python command. Requires the Jenkins :jenkins-plugins:`Python plugin
    <python>`.

    :arg str parameter: the python command to execute

    Example:

    .. literalinclude:: /../../tests/builders/fixtures/python.yaml
       :language: yaml

    """
    python = XML.SubElement(xml_parent, "hudson.plugins.python.Python")
    XML.SubElement(python, "command").text = data


def copyartifact(registry, xml_parent, data):
    """yaml: copyartifact

    Copy artifact from another project. Requires the :jenkins-plugins:`Copy
    Artifact plugin <copyartifact>`.

    Please note using the multijob-build for which-build argument requires
    the :jenkins-plugins:`Multijob plugin <jenkins-multijob-plugin>`

    :arg str project: Project to copy from
    :arg str filter: what files to copy
    :arg str target: Target base directory for copy, blank means use workspace
    :arg bool flatten: Flatten directories (default false)
    :arg bool optional: If the artifact is missing (for any reason) and
        optional is true, the build won't fail because of this builder
        (default false)
    :arg bool do-not-fingerprint: Disable automatic fingerprinting of copied
        artifacts (default false)
    :arg str which-build: which build to get artifacts from
        (optional, default last-successful)

        :which-build values:
            * **last-successful**
            * **last-completed**
            * **specific-build**
            * **last-saved**
            * **upstream-build**
            * **permalink**
            * **workspace-latest**
            * **build-param**
            * **downstream-build**
            * **multijob-build**

    :arg str build-number: specifies the build number to get when
        when specific-build is specified as which-build
    :arg str permalink: specifies the permalink to get when
        permalink is specified as which-build

        :permalink values:
            * **last**
            * **last-stable**
            * **last-successful**
            * **last-failed**
            * **last-unstable**
            * **last-unsuccessful**

    :arg bool stable: specifies to get only last stable build when
        last-successful is specified as which-build
    :arg bool fallback-to-last-successful: specifies to fallback to
        last successful build when upstream-build is specified as which-build
    :arg str param: specifies to use a build parameter to get the build when
        build-param is specified as which-build
    :arg str upstream-project-name: specifies the project name of downstream
        when downstream-build is specified as which-build
    :arg str upstream-build-number: specifies the number of the build to
        find its downstream build when downstream-build is specified as
        which-build
    :arg str parameter-filters: Filter matching jobs based on these
        parameters (optional)
    :arg str exclude: Specify paths or patterns of artifacts to
        exclude, even if specified in "Artifacts to copy". (default '')
    :arg str result-var-suffix: The build number of the selected build
        will be recorded into the variable named
        COPYARTIFACT_BUILD_NUMBER_(SUFFIX)
        for later build steps to reference. (default '')

    Example:

    .. literalinclude:: ../../tests/builders/fixtures/copy-artifact001.yaml
       :language: yaml

    Multijob Example:

    .. literalinclude:: ../../tests/builders/fixtures/copy-artifact004.yaml
       :language: yaml
    """
    t = XML.SubElement(xml_parent, "hudson.plugins.copyartifact.CopyArtifact")
    mappings = [
        # Warning: this only works with copy artifact version 1.26+,
        # for copy artifact version 1.25- the 'projectName' element needs
        # to be used instead of 'project'
        ("project", "project", None),
        ("filter", "filter", ""),
        ("target", "target", ""),
        ("flatten", "flatten", False),
        ("optional", "optional", False),
        ("do-not-fingerprint", "doNotFingerprintArtifacts", False),
        ("parameter-filters", "parameters", ""),
        ("exclude", "exclude", ""),
        ("result-var-suffix", "resultVariableSuffix", ""),
    ]
    helpers.convert_mapping_to_xml(t, data, mappings, fail_required=True)
    helpers.copyartifact_build_selector(t, data)


def change_assembly_version(registry, xml_parent, data):
    """yaml: change-assembly-version
    Change the assembly version.
    Requires the Jenkins :jenkins-plugins:`Change Assembly Version
    <change-assembly-version-plugin>`.

    :arg str version: Set the new version number for replace (default 1.0.0)
    :arg str assemblyFile: The file name to search (default AssemblyInfo.cs)

    Minimal Example:

    .. literalinclude::
        /../../tests/builders/fixtures/changeassemblyversion-minimal.yaml
       :language: yaml

    Full Example:

    .. literalinclude::
        /../../tests/builders/fixtures/changeassemblyversion-full.yaml
       :language: yaml
    """

    cav_builder_tag = (
        "org.jenkinsci.plugins.changeassemblyversion." "ChangeAssemblyVersion"
    )
    cav = XML.SubElement(xml_parent, cav_builder_tag)
    mappings = [
        ("version", "task", "1.0.0"),
        ("assembly-file", "assemblyFile", "AssemblyInfo.cs"),
    ]
    helpers.convert_mapping_to_xml(cav, data, mappings, fail_required=True)


def fingerprint(registry, xml_parent, data):
    """yaml: fingerprint
    Adds the ability to generate fingerprints as build steps instead of waiting
    for a build to complete.

    Requires the Jenkins :jenkins-plugins:`Fingerprint Plugin
    <create-fingerprint>`.

    :arg str targets: Files to fingerprint (default '')

    Full Example:

    .. literalinclude::
        /../../tests/builders/fixtures/fingerprint-full.yaml
       :language: yaml

    Minimal Example:

    .. literalinclude::
        /../../tests/builders/fixtures/fingerprint-minimal.yaml
       :language: yaml
    """

    fingerprint = XML.SubElement(
        xml_parent, "hudson.plugins.createfingerprint.CreateFingerprint"
    )
    fingerprint.set("plugin", "create-fingerprint")

    mapping = [("targets", "targets", "")]
    helpers.convert_mapping_to_xml(fingerprint, data, mapping, fail_required=True)


def ant(registry, xml_parent, data):
    """yaml: ant
    Execute an ant target. Requires the Jenkins :jenkins-plugins:`Ant Plugin
    <ant>`.

    To setup this builder you can either reference the list of targets
    or use named parameters. Below is a description of both forms:

    *1) Listing targets:*

    After the ant directive, simply pass as argument a space separated list
    of targets to build.

    :Parameter: space separated list of Ant targets

    Example to call two Ant targets:

    .. literalinclude:: ../../tests/builders/fixtures/ant001.yaml
       :language: yaml

    The build file would be whatever the Jenkins Ant Plugin is set to use
    per default (i.e build.xml in the workspace root).

    *2) Using named parameters:*

    :arg str targets: the space separated list of ANT targets.
    :arg str buildfile: the path to the ANT build file.
    :arg list properties: Passed to ant script using -Dkey=value (optional)
    :arg str ant-name: the name of the ant installation,
        (default 'default') (optional)
    :arg str java-opts: java options for ant, can have multiples,
        must be in quotes (optional)


    Example specifying the build file too and several targets:

    .. literalinclude:: ../../tests/builders/fixtures/ant002.yaml
       :language: yaml
    """
    ant = XML.SubElement(xml_parent, "hudson.tasks.Ant")

    if type(data) is str:
        # Support for short form: -ant: "target"
        data = {"targets": data}

    mapping = [
        ("targets", "targets", None),
        ("buildfile", "buildFile", None),
        ("ant-name", "antName", "default"),
    ]
    helpers.convert_mapping_to_xml(ant, data, mapping, fail_required=False)

    mapping = []
    for setting, value in sorted(data.items()):
        if setting == "properties":
            properties = value
            prop_string = ""
            for prop, val in properties.items():
                prop_string += "%s=%s\n" % (prop, val)
            mapping.append(("", "properties", prop_string))
        if setting == "java-opts":
            jopt_string = "\n".join(value)
            mapping.append(("", "antOpts", jopt_string))

    helpers.convert_mapping_to_xml(ant, data, mapping, fail_required=True)


def trigger_remote(registry, xml_parent, data):
    """yaml: trigger-remote
    Trigger build of job on remote Jenkins instance.

    Requires the Jenkins :jenkins-plugins:`Parameterized Remote Trigger Plugin
    <Parameterized-Remote-Trigger>`

    Please note that this plugin requires system configuration on the Jenkins
    Master that is unavailable from individual job views; specifically, one
    must add remote jenkins servers whose 'Display Name' field are what make up
    valid fields on the `remote-jenkins-name` attribute below.

    :arg str remote-jenkins-name: the remote Jenkins server (required)
    :arg str job: the Jenkins project to trigger on the remote Jenkins server
        (required)
    :arg bool should-not-fail-build: if true, remote job failure will not lead
        current job to fail (default false)
    :arg bool prevent-remote-build-queue: if true, wait to trigger remote
        builds until no other builds (default false)
    :arg bool block: whether to wait for the trigger jobs to finish or not
        (default true)
    :arg str poll-interval: polling interval in seconds for checking statues of
        triggered remote job, only necessary if current job is configured to
        block (default 10)
    :arg str connection-retry-limit: number of connection attempts to remote
        Jenkins server before giving up. (default 5)
    :arg bool enhanced-logging: if this option is enabled,
        the console output of the remote job is also logged. (default false)
    :arg str predefined-parameters: predefined parameters to send to the remote
        job when triggering it (optional)
    :arg str property-file: file in workspace of current job containing
        additional parameters to be set on remote job
        (optional)

    Example:

    .. literalinclude::
        /../../tests/builders/fixtures/trigger-remote/trigger-remote001.yaml
       :language: yaml
    """
    triggerr = XML.SubElement(
        xml_parent,
        "org.jenkinsci.plugins."
        "ParameterizedRemoteTrigger."
        "RemoteBuildConfiguration",
    )

    mappings = [
        ("remote-jenkins-name", "remoteJenkinsName", None),
        ("token", "token", ""),
        ("job", "job", None),
        ("should-not-fail-build", "shouldNotFailBuild", False),
        ("poll-interval", "pollInterval", 10),
        ("connection-retry-limit", "connectionRetryLimit", 5),
        ("enhanced-logging", "enhancedLogging", False),
        ("prevent-remote-build-queue", "preventRemoteBuildQueue", False),
        ("block", "blockBuildUntilComplete", True),
    ]
    helpers.convert_mapping_to_xml(triggerr, data, mappings, fail_required=True)

    mappings = []
    if "predefined-parameters" in data:
        parameters = data.get("predefined-parameters", "")
        XML.SubElement(triggerr, "parameters").text = parameters
        params_list = parameters.split("\n")

        parameter_list = XML.SubElement(triggerr, "parameterList")
        for param in params_list:
            if param == "":
                continue
            tmp = XML.SubElement(parameter_list, "string")
            tmp.text = param

    if "property-file" in data and data["property-file"] != "":
        mappings.append(("", "loadParamsFromFile", "true"))
        mappings.append(("property-file", "parameterFile", None))
    else:
        mappings.append(("", "loadParamsFromFile", "false"))

    mappings.append(("", "overrideAuth", "false"))

    helpers.convert_mapping_to_xml(triggerr, data, mappings, fail_required=True)


def trigger_builds(registry, xml_parent, data):
    """yaml: trigger-builds
    Trigger builds of other jobs.

    Requires the Jenkins :jenkins-plugins:`Parameterized Trigger Plugin
    <parameterized-trigger>`.

    :arg list project: the Jenkins project to trigger
    :arg str predefined-parameters: key/value pairs to be passed to the job
        (optional)
    :arg list bool-parameters:

        :Bool:
            * **name** (`str`) -- Parameter name
            * **value** (`bool`) -- Value to set (default false)

    :arg str property-file:
        Pass properties from file to the other job (optional)
    :arg bool property-file-fail-on-missing:
        Don't trigger if any files are missing (default true)
    :arg bool current-parameters: Whether to include the parameters passed
        to the current build to the triggered job.
    :arg str node-label-name: Define a name for the NodeLabel parameter to be
        set. Used in conjunction with node-label. Requires NodeLabel Parameter
        Plugin (optional)
    :arg str node-label: Label of the nodes where build should be triggered.
        Used in conjunction with node-label-name.  Requires NodeLabel Parameter
        Plugin (optional)
    :arg str restrict-matrix-project: Filter that restricts the subset
        of the combinations that the triggered job will run (optional)
    :arg bool svn-revision: Whether to pass the svn revision to the triggered
        job (optional)
    :arg dict git-revision: Passes git revision to the triggered job
        (optional).

        * **combine-queued-commits** (bool): Whether to combine queued git
          hashes or not (default false)
    :arg bool block: whether to wait for the triggered jobs to finish or not
        (default false)
    :arg dict block-thresholds: Fail builds and/or mark as failed or unstable
        based on thresholds. Only apply if block parameter is true (optional)

        :block-thresholds:
            * **build-step-failure-threshold** (`str`) - build step failure
              threshold, valid values are 'never', 'SUCCESS', 'UNSTABLE', or
              'FAILURE'. (default 'FAILURE')
            * **unstable-threshold** (`str`) - unstable threshold, valid
              values are 'never', 'SUCCESS', 'UNSTABLE', or 'FAILURE'.
              (default 'UNSTABLE')
            * **failure-threshold** (`str`) - overall failure threshold, valid
              values are 'never', 'SUCCESS', 'UNSTABLE', or 'FAILURE'.
              (default 'FAILURE')

    :arg bool same-node: Use the same node for the triggered builds that was
        used for this build (optional)
    :arg list parameter-factories: list of parameter factories

        :Factory:
            * **factory** (`str`) **filebuild** -- For every property file,
              invoke one build
            * **file-pattern** (`str`) -- File wildcard pattern
            * **no-files-found-action** (`str`) -- Action to perform when
              no files found. Valid values 'FAIL', 'SKIP', or 'NOPARMS'.
              (default 'SKIP')

        :Factory:
            * **factory** (`str`) **binaryfile** -- For every matching
              file, invoke one build
            * **file-pattern** (`str`) -- Artifact ID of the artifact
            * **no-files-found-action** (`str`) -- Action to perform when
              no files found. Valid values 'FAIL', 'SKIP', or 'NOPARMS'.
              (default 'SKIP')

        :Factory:
            * **factory** (`str`) **counterbuild** -- Invoke i=0...N builds
            * **from** (`int`) -- Artifact ID of the artifact
            * **to** (`int`) -- Version of the artifact
            * **step** (`int`) -- Classifier of the artifact
            * **parameters** (`str`) -- KEY=value pairs, one per line
              (default '')
            * **validation-fail** (`str`) -- Action to perform when
              stepping validation fails. Valid values 'FAIL', 'SKIP', or
              'NOPARMS'. (default 'FAIL')

        :Factory:
            * **factory** (`str`) **allnodesforlabel** -- Trigger a build
              on all nodes having specific label. Requires NodeLabel
              Parameter Plugin (optional)
            * **name** (`str`) -- Name of the parameter to set (optional)
            * **node-label** (`str`) -- Label of the nodes where build
              should be triggered
            * **ignore-offline-nodes** (`bool`) -- Don't trigger build on
              offline nodes (default true)

        :Factory:
            * **factory** (`str`) **allonlinenodes** -- Trigger a build on
              every online node. Requires NodeLabel Parameter Plugin (optional)

    Examples:

    Basic usage with yaml list of projects.

    .. literalinclude::
        /../../tests/builders/fixtures/trigger-builds/project-list.yaml
       :language: yaml

    Basic usage with passing svn revision through.

    .. literalinclude:: /../../tests/builders/fixtures/trigger-builds001.yaml
       :language: yaml

    Basic usage with passing git revision through.

    .. literalinclude:: /../../tests/builders/fixtures/trigger-builds006.yaml
       :language: yaml

    Example with all supported parameter factories.

    .. literalinclude::
        /../../tests/builders/fixtures/trigger-builds-configfactory-multi.yaml
       :language: yaml
    """
    tbuilder = XML.SubElement(
        xml_parent, "hudson.plugins.parameterizedtrigger." "TriggerBuilder"
    )
    configs = XML.SubElement(tbuilder, "configs")
    for project_def in data:
        if "project" not in project_def or project_def["project"] == "":
            logger.debug("No project specified - skipping trigger-build")
            continue
        tconfig = XML.SubElement(
            configs,
            "hudson.plugins.parameterizedtrigger." "BlockableBuildTriggerConfig",
        )
        tconfigs = XML.SubElement(tconfig, "configs")
        if project_def.get("current-parameters"):
            XML.SubElement(
                tconfigs,
                "hudson.plugins.parameterizedtrigger." "CurrentBuildParameters",
            )
        if project_def.get("svn-revision"):
            XML.SubElement(
                tconfigs,
                "hudson.plugins.parameterizedtrigger."
                "SubversionRevisionBuildParameters",
            )

        if project_def.get("git-revision"):
            helpers.append_git_revision_config(tconfigs, project_def["git-revision"])

        if project_def.get("same-node"):
            XML.SubElement(
                tconfigs, "hudson.plugins.parameterizedtrigger." "NodeParameters"
            )
        if "property-file" in project_def:
            params = XML.SubElement(
                tconfigs, "hudson.plugins.parameterizedtrigger." "FileBuildParameters"
            )
            mapping = [
                ("property-file", "propertiesFile", None),
                ("property-file-fail-on-missing", "failTriggerOnMissing", True),
            ]
            helpers.convert_mapping_to_xml(
                params, project_def, mapping, fail_required=True
            )

        if "predefined-parameters" in project_def:
            params = XML.SubElement(
                tconfigs,
                "hudson.plugins.parameterizedtrigger." "PredefinedBuildParameters",
            )
            mapping = [("predefined-parameters", "properties", None)]
            helpers.convert_mapping_to_xml(
                params, project_def, mapping, fail_required=True
            )

        if "bool-parameters" in project_def:
            params = XML.SubElement(
                tconfigs, "hudson.plugins.parameterizedtrigger." "BooleanParameters"
            )
            configs = XML.SubElement(params, "configs")
            for bool_param in project_def["bool-parameters"]:
                param = XML.SubElement(
                    configs,
                    "hudson.plugins.parameterizedtrigger." "BooleanParameterConfig",
                )
                mapping = [("name", "name", None), ("value", "value", False)]
                helpers.convert_mapping_to_xml(
                    param, bool_param, mapping, fail_required=True
                )

        if "node-label-name" in project_def and "node-label" in project_def:
            node = XML.SubElement(
                tconfigs,
                "org.jvnet.jenkins.plugins."
                "nodelabelparameter.parameterizedtrigger."
                "NodeLabelBuildParameter",
            )
            mapping = [
                ("node-label-name", "name", None),
                ("node-label", "nodeLabel", None),
            ]
            helpers.convert_mapping_to_xml(
                node, project_def, mapping, fail_required=True
            )

        if "restrict-matrix-project" in project_def:
            params = XML.SubElement(
                tconfigs,
                "hudson.plugins.parameterizedtrigger."
                "matrix.MatrixSubsetBuildParameters",
            )
            mapping = [("restrict-matrix-project", "filter", None)]
            helpers.convert_mapping_to_xml(
                params, project_def, mapping, fail_required=True
            )

        if len(list(tconfigs)) == 0:
            tconfigs.set("class", "java.util.Collections$EmptyList")

        if "parameter-factories" in project_def:
            fconfigs = XML.SubElement(tconfig, "configFactories")

            supported_factories = [
                "filebuild",
                "binaryfile",
                "counterbuild",
                "allnodesforlabel",
                "allonlinenodes",
            ]
            supported_actions = ["SKIP", "NOPARMS", "FAIL"]
            for factory in project_def["parameter-factories"]:

                if factory["factory"] not in supported_factories:
                    raise InvalidAttributeError(
                        "factory", factory["factory"], supported_factories
                    )

                if factory["factory"] == "filebuild":
                    params = XML.SubElement(
                        fconfigs,
                        "hudson.plugins.parameterizedtrigger."
                        "FileBuildParameterFactory",
                    )
                if factory["factory"] == "binaryfile":
                    params = XML.SubElement(
                        fconfigs,
                        "hudson.plugins.parameterizedtrigger."
                        "BinaryFileParameterFactory",
                    )
                    mapping = [("parameter-name", "parameterName", None)]
                    helpers.convert_mapping_to_xml(
                        params, factory, mapping, fail_required=True
                    )

                if (
                    factory["factory"] == "filebuild"
                    or factory["factory"] == "binaryfile"
                ):
                    mapping = [
                        ("file-pattern", "filePattern", None),
                        (
                            "no-files-found-action",
                            "noFilesFoundAction",
                            "SKIP",
                            supported_actions,
                        ),
                    ]
                    helpers.convert_mapping_to_xml(
                        params, factory, mapping, fail_required=True
                    )

                if factory["factory"] == "counterbuild":
                    params = XML.SubElement(
                        fconfigs,
                        "hudson.plugins.parameterizedtrigger."
                        "CounterBuildParameterFactory",
                    )
                    mapping = [
                        ("from", "from", None),
                        ("to", "to", None),
                        ("step", "step", None),
                        ("parameters", "paramExpr", ""),
                        (
                            "validation-fail",
                            "validationFail",
                            "FAIL",
                            supported_actions,
                        ),
                    ]
                    helpers.convert_mapping_to_xml(
                        params, factory, mapping, fail_required=True
                    )

                if factory["factory"] == "allnodesforlabel":
                    params = XML.SubElement(
                        fconfigs,
                        "org.jvnet.jenkins.plugins.nodelabelparameter."
                        "parameterizedtrigger."
                        "AllNodesForLabelBuildParameterFactory",
                    )
                    mapping = [
                        ("name", "name", ""),
                        ("node-label", "nodeLabel", None),
                        ("ignore-offline-nodes", "ignoreOfflineNodes", True),
                    ]
                    helpers.convert_mapping_to_xml(
                        params, factory, mapping, fail_required=True
                    )

                if factory["factory"] == "allonlinenodes":
                    params = XML.SubElement(
                        fconfigs,
                        "org.jvnet.jenkins.plugins.nodelabelparameter."
                        "parameterizedtrigger."
                        "AllNodesBuildParameterFactory",
                    )

        projects = XML.SubElement(tconfig, "projects")
        if isinstance(project_def["project"], list):
            projects.text = ",".join(project_def["project"])
        else:
            projects.text = project_def["project"]

        mapping = [
            ("", "condition", "ALWAYS"),
            ("", "triggerWithNoParameters", False),
            ("", "buildAllNodesWithLabel", False),
        ]
        helpers.convert_mapping_to_xml(tconfig, {}, mapping, fail_required=True)

        block = project_def.get("block", False)
        if block:
            block = XML.SubElement(tconfig, "block")
            supported_thresholds = [
                [
                    "build-step-failure-threshold",
                    "buildStepFailureThreshold",
                    "FAILURE",
                ],
                ["unstable-threshold", "unstableThreshold", "UNSTABLE"],
                ["failure-threshold", "failureThreshold", "FAILURE"],
            ]
            supported_threshold_values = [
                "never",
                hudson_model.SUCCESS["name"],
                hudson_model.UNSTABLE["name"],
                hudson_model.FAILURE["name"],
            ]
            thrsh = project_def.get("block-thresholds", False)
            for toptname, txmltag, tvalue in supported_thresholds:
                if thrsh:
                    tvalue = thrsh.get(toptname, tvalue)
                if tvalue.lower() == supported_threshold_values[0]:
                    continue
                if tvalue.upper() not in supported_threshold_values:
                    raise InvalidAttributeError(
                        toptname, tvalue, supported_threshold_values
                    )
                th = XML.SubElement(block, txmltag)
                mapping = [
                    ("name", "name", None),
                    ("ordinal", "ordinal", None),
                    ("color", "color", None),
                    ("", "completeBuild", True),
                ]
                helpers.convert_mapping_to_xml(
                    th,
                    hudson_model.THRESHOLDS[tvalue.upper()],
                    mapping,
                    fail_required=True,
                )

    # If configs is empty, remove the entire tbuilder tree.
    if len(configs) == 0:
        logger.debug("Pruning empty TriggerBuilder tree.")
        xml_parent.remove(tbuilder)


def builders_from(registry, xml_parent, data):
    """yaml: builders-from
    Use builders from another project.

    Requires the Jenkins :jenkins-plugins:`Template Project Plugin
    <template-project>`.

    :arg str projectName: the name of the other project

    Example:

    .. literalinclude:: ../../tests/builders/fixtures/builders-from.yaml
       :language: yaml
    """
    pbs = XML.SubElement(xml_parent, "hudson.plugins.templateproject.ProxyBuilder")
    mapping = [("", "projectName", data)]
    helpers.convert_mapping_to_xml(pbs, {}, mapping, fail_required=True)


def http_request(registry, xml_parent, data):
    """yaml: http-request
    This plugin sends a http request to an url with some parameters.

    Requires the Jenkins :jenkins-plugins:`HTTP Request Plugin
    <http_request>`.

    :arg str url: Specify an URL to be requested (required)
    :arg str mode: The http mode of the request (default GET)

        :mode values:
            * **GET**
            * **POST**
            * **PUT**
            * **DELETE**
            * **HEAD**
    :arg str content-type: Add 'Content-type: foo' HTTP request headers
        where foo is the http content-type the request is using.
        (default NOT_SET)
    :arg str accept-type: Add 'Accept: foo' HTTP request headers
        where foo is the http content-type to accept (default NOT_SET)

        :content-type and accept-type values:
            * **NOT_SET**
            * **TEXT_HTML**
            * **APPLICATION_JSON**
            * **APPLICATION_TAR**
            * **APPLICATION_ZIP**
            * **APPLICATION_OCTETSTREAM**
    :arg str output-file: Name of the file in which to write response data
        (default '')
    :arg int time-out: Specify a timeout value in seconds (default 0)
    :arg bool console-log: This allows you to turn off writing the response
        body to the log (default false)
    :arg bool pass-build: Should build parameters be passed to the URL
        being called (default false)
    :arg str valid-response-codes: Configure response code to mark an
        execution as success. You can configure simple code such as "200"
        or multiple codes separated by comma(',') e.g. "200,404,500"
        Interval of codes should be in format From:To e.g. "100:399".
        The default (as if empty) is to fail to 4xx and 5xx.
        That means success from 100 to 399 "100:399"
        To ignore any response code use "100:599". (default '')
    :arg str valid-response-content: If set response must contain this string
        to mark an execution as success (default '')
    :arg str authentication-key: Authentication that will be used before this
        request. Authentications are created in global configuration under a
        key name that is selected here.
    :arg list custom-headers: list of header parameters

        :custom-header:
            * **name** (`str`) -- Name of the header
            * **value** (`str`) -- Value of the header

    Example:

    .. literalinclude:: ../../tests/builders/fixtures/http-request-minimal.yaml
       :language: yaml

    .. literalinclude::
       ../../tests/builders/fixtures/http-request-full.yaml
       :language: yaml
    """

    http_request = XML.SubElement(
        xml_parent, "jenkins.plugins.http__request.HttpRequest"
    )
    http_request.set("plugin", "http_request")

    valid_modes = ["GET", "POST", "PUT", "DELETE", "HEAD"]
    valid_types = [
        "NOT_SET",
        "TEXT_HTML",
        "APPLICATION_JSON",
        "APPLICATION_TAR",
        "APPLICATION_ZIP",
        "APPLICATION_OCTETSTREAM",
    ]

    mappings = [
        ("url", "url", None),
        ("mode", "httpMode", "GET", valid_modes),
        ("content-type", "contentType", "NOT_SET", valid_types),
        ("accept-type", "acceptType", "NOT_SET", valid_types),
        ("output-file", "outputFile", ""),
        ("console-log", "consoleLogResponseBody", False),
        ("pass-build", "passBuildParameters", False),
        ("time-out", "timeout", 0),
        ("valid-response-codes", "validResponseCodes", ""),
        ("valid-response-content", "validResponseContent", ""),
    ]
    helpers.convert_mapping_to_xml(http_request, data, mappings, fail_required=True)

    if "authentication-key" in data:
        XML.SubElement(http_request, "authentication").text = data["authentication-key"]

    if "custom-headers" in data:
        customHeader = XML.SubElement(http_request, "customHeaders")
        header_mappings = [("name", "name", None), ("value", "value", None)]
        for customhead in data["custom-headers"]:
            pair = XML.SubElement(customHeader, "pair")
            helpers.convert_mapping_to_xml(
                pair, customhead, header_mappings, fail_required=True
            )


def inject(registry, xml_parent, data):
    """yaml: inject
    Inject an environment for the job.

    Requires the Jenkins :jenkins-plugins:`EnvInject Plugin <envinject>`.

    :arg str properties-file: the name of the property file (optional)
    :arg str properties-content: the properties content (optional)
    :arg str script-file: the name of a script file to run (optional)
    :arg str script-content: the script content (optional)

    Example:

    .. literalinclude:: ../../tests/builders/fixtures/inject.yaml
       :language: yaml
    """
    eib = XML.SubElement(xml_parent, "EnvInjectBuilder")
    info = XML.SubElement(eib, "info")
    mapping = [
        ("properties-file", "propertiesFilePath", None),
        ("properties-content", "propertiesContent", None),
        ("script-file", "scriptFilePath", None),
        ("script-content", "scriptContent", None),
    ]
    helpers.convert_mapping_to_xml(info, data, mapping, fail_required=False)


def kmap(registry, xml_parent, data):
    """yaml: kmap
    Publish mobile applications to your Keivox KMAP Private Mobile App Store.

    Requires the Jenkins :jenkins-plugins:`Keivox KMAP Private Mobile App Store
    Plugin <kmap-jenkins>`.

    :arg str username: KMAP's user email with permissions to upload/publish
        applications to KMAP (required)
    :arg str password:  Password for the KMAP user uploading/publishing
        applications (required)
    :arg str url: KMAP's url. This url must always end with "/kmap-client/".
        For example: http://testing.example.org/kmap-client/ (required)
    :arg str categories: Categories' names. If you want to add the application
        to more than one category, write the categories between commas.
        (required)
    :arg str file-path: Path to the application's file (required)
    :arg str app-name: KMAP's application name (required)
    :arg str bundle: Bundle indentifier (default '')
    :arg str version: Application's version (required)
    :arg str description: Application's description (default '')
    :arg str icon-path: Path to the application's icon (default '')
    :arg bool publish-optional: Publish application after it has been uploaded
        to KMAP (default false)

        :publish-optional:
            * **groups** ('str') -- groups' names to publish the application
                (default '')
            * **users** ('str') -- users' names to publish the application
                (default '')
            * **notify-users** ('bool') -- Send notifications to the users and
                groups when publishing the application (default false)

    Minimal Example:

    .. literalinclude:: ../../tests/builders/fixtures/kmap-minimal.yaml
       :language: yaml

    Full Example:

    .. literalinclude:: ../../tests/builders/fixtures/kmap-full.yaml
       :language: yaml
    """
    kmap = XML.SubElement(xml_parent, "org.jenkinsci.plugins.KmapJenkinsBuilder")

    kmap.set("plugin", "kmap-jenkins")
    publish = data.get("publish-optional", False)

    mapping = [
        ("username", "username", None),
        ("password", "password", None),
        ("url", "kmapClient", None),
        ("categories", "categories", None),
        ("file-path", "filePath", None),
        ("app-name", "appName", None),
        ("bundle", "bundle", ""),
        ("version", "version", None),
        ("description", "description", ""),
        ("icon-path", "iconPath", ""),
    ]
    helpers.convert_mapping_to_xml(kmap, data, mapping, fail_required=True)

    if publish is True:
        publish_optional = XML.SubElement(kmap, "publishOptional")
        publish_mapping = [
            ("groups", "teams", ""),
            ("users", "users", ""),
            ("notify-users", "sendNotifications", False),
        ]
        helpers.convert_mapping_to_xml(
            publish_optional, data, publish_mapping, fail_required=True
        )


def artifact_resolver(registry, xml_parent, data):
    """yaml: artifact-resolver
    Allows one to resolve artifacts from a maven repository like nexus
    (without having maven installed)

    Requires the Jenkins :jenkins-plugins:`Repository Connector Plugin
    <repository-connector>`.

    :arg bool fail-on-error: Whether to fail the build on error (default false)
    :arg bool repository-logging: Enable repository logging (default false)
    :arg str target-directory: Where to resolve artifacts to (required)
    :arg list artifacts: list of artifacts to resolve

        :Artifact:
            * **group-id** (`str`) -- Group ID of the artifact (required)
            * **artifact-id** (`str`) -- Artifact ID of the artifact (required)
            * **version** (`str`) -- Version of the artifact (required)
            * **classifier** (`str`) -- Classifier of the artifact (default '')
            * **extension** (`str`) -- Extension of the artifact
              (default 'jar')
            * **target-file-name** (`str`) -- What to name the artifact
              (default '')

    Minimal Example:

    .. literalinclude::
        ../../tests/builders/fixtures/artifact-resolver-minimal.yaml
       :language: yaml

    Full Example:

    .. literalinclude::
        ../../tests/builders/fixtures/artifact-resolver-full.yaml
       :language: yaml
    """
    ar = XML.SubElement(
        xml_parent, "org.jvnet.hudson.plugins.repositoryconnector.ArtifactResolver"
    )
    mapping = [
        ("target-directory", "targetDirectory", None),
        ("fail-on-error", "failOnError", False),
        ("repository-logging", "enableRepoLogging", False),
        ("", "snapshotUpdatePolicy", "never"),
        ("", "releaseUpdatePolicy", "never"),
        ("", "snapshotChecksumPolicy", "warn"),
        ("", "releaseChecksumPolicy", "warn"),
    ]
    helpers.convert_mapping_to_xml(ar, data, mapping, fail_required=True)

    artifact_top = XML.SubElement(ar, "artifacts")
    artifacts = data["artifacts"]
    artifacts_mapping = [
        ("group-id", "groupId", None),
        ("artifact-id", "artifactId", None),
        ("version", "version", None),
        ("classifier", "classifier", ""),
        ("extension", "extension", "jar"),
        ("target-file-name", "targetFileName", ""),
    ]
    for artifact in artifacts:
        rcartifact = XML.SubElement(
            artifact_top, "org.jvnet.hudson.plugins.repositoryconnector.Artifact"
        )
        helpers.convert_mapping_to_xml(
            rcartifact, artifact, artifacts_mapping, fail_required=True
        )


def doxygen(registry, xml_parent, data):
    """yaml: doxygen
    Builds doxygen HTML documentation.

    Requires the Jenkins :jenkins-plugins:`Doxygen plugin <doxygen>`.

    :arg str doxyfile: The doxyfile path (required)
    :arg str install: The doxygen installation to use (required)
    :arg bool ignore-failure: Keep executing build even on doxygen generation
        failure (default false)
    :arg bool unstable-warning: Mark the build as unstable if warnings are
        generated (default false)

    Example:

    .. literalinclude:: /../../tests/builders/fixtures/doxygen001.yaml
       :language: yaml

    """
    doxygen = XML.SubElement(xml_parent, "hudson.plugins.doxygen.DoxygenBuilder")
    mappings = [
        ("doxyfile", "doxyfilePath", None),
        ("install", "installationName", None),
        ("ignore-failure", "continueOnBuildFailure", False),
        ("unstable-warning", "unstableIfWarnings", False),
    ]
    helpers.convert_mapping_to_xml(doxygen, data, mappings, fail_required=True)


def gradle(registry, xml_parent, data):
    """yaml: gradle
    Execute gradle tasks.

    Requires the Jenkins :jenkins-plugins:`Gradle Plugin <gradle>`.

    :arg str tasks: List of tasks to execute
    :arg str gradle-name: Use a custom gradle name (default '')
    :arg bool wrapper: use gradle wrapper (default false)
    :arg bool executable: make gradlew executable (default false)
    :arg list switches: Switches for gradle, can have multiples
    :arg bool use-root-dir: Whether to run the gradle script from the
        top level directory or from a different location (default false)
    :arg str root-build-script-dir: If your workspace has the
        top-level build.gradle in somewhere other than the module
        root directory, specify the path (relative to the module
        root) here, such as ${workspace}/parent/ instead of just
        ${workspace}.
    :arg str build-file: name of gradle build script (default 'build.gradle')

    Example:

    .. literalinclude:: ../../tests/builders/fixtures/gradle.yaml
       :language: yaml
    """
    gradle = XML.SubElement(xml_parent, "hudson.plugins.gradle.Gradle")

    XML.SubElement(gradle, "description").text = ""

    mappings = [
        ("build-file", "buildFile", "build.gradle"),
        ("tasks", "tasks", None),
        ("root-build-script-dir", "rootBuildScriptDir", ""),
        ("gradle-name", "gradleName", ""),
        ("wrapper", "useWrapper", False),
        ("executable", "makeExecutable", False),
        ("use-root-dir", "fromRootBuildScriptDir", False),
    ]
    helpers.convert_mapping_to_xml(gradle, data, mappings, fail_required=True)

    XML.SubElement(gradle, "switches").text = "\n".join(data.get("switches", []))


def _groovy_common_scriptSource(data):
    """Helper function to generate the XML element common to groovy builders
    """

    scriptSource = XML.Element("scriptSource")
    if "command" in data and "file" in data:
        raise JenkinsJobsException("Use just one of 'command' or 'file'")

    if "command" in data:
        mapping = [("command", "command", None)]
        helpers.convert_mapping_to_xml(scriptSource, data, mapping, fail_required=True)
        scriptSource.set("class", "hudson.plugins.groovy.StringScriptSource")
    elif "file" in data:
        mapping = [("file", "scriptFile", None)]
        helpers.convert_mapping_to_xml(scriptSource, data, mapping, fail_required=True)
        scriptSource.set("class", "hudson.plugins.groovy.FileScriptSource")
    else:
        raise JenkinsJobsException("A groovy command or file is required")

    return scriptSource


def groovy(registry, xml_parent, data):
    """yaml: groovy
    Execute a groovy script or command.

    Requires the Jenkins :jenkins-plugins:`Groovy Plugin <groovy>`.

    :arg str file: Groovy file to run. (Alternative: you can chose a command
        instead)
    :arg str command: Groovy command to run. (Alternative: you can chose a
        script file instead)
    :arg str version: Groovy version to use. (default '(Default)')
    :arg str parameters: Parameters for the Groovy executable. (default '')
    :arg str script-parameters: These parameters will be passed to the script.
        (default '')
    :arg str properties: Instead of passing properties using the -D parameter
        you can define them here. (default '')
    :arg str java-opts: Direct access to JAVA_OPTS. Properties allows only
        -D properties, while sometimes also other properties like -XX need to
        be setup. It can be done here. This line is appended at the end of
        JAVA_OPTS string. (default '')
    :arg str class-path: Specify script classpath here. Each line is one
        class path item. (default '')

    Minimal Example:

    .. literalinclude:: ../../tests/builders/fixtures/groovy-minimal.yaml
       :language: yaml


    Full Example:

    .. literalinclude:: ../../tests/builders/fixtures/groovy-full.yaml
       :language: yaml
    """

    root_tag = "hudson.plugins.groovy.Groovy"
    groovy = XML.SubElement(xml_parent, root_tag)
    groovy.append(_groovy_common_scriptSource(data))

    mappings = [
        ("version", "groovyName", "(Default)"),
        ("parameters", "parameters", ""),
        ("script-parameters", "scriptParameters", ""),
        ("properties", "properties", ""),
        ("java-opts", "javaOpts", ""),
        ("class-path", "classPath", ""),
    ]
    helpers.convert_mapping_to_xml(groovy, data, mappings, fail_required=True)


def system_groovy(registry, xml_parent, data):
    """yaml: system-groovy
    Execute a system groovy script or command.

    Requires the Jenkins :jenkins-plugins:`Groovy Plugin <groovy>`.

    :arg str file: Groovy file to run. (Alternative: you can chose a command
        instead)
    :arg str command: Groovy command to run. (Alternative: you can chose a
        script file instead)
    :arg str bindings: Define variable bindings (in the properties file
        format). Specified variables can be addressed from the script.
        (optional)
    :arg str class-path: Specify script classpath here. Each line is one class
        path item. (optional)

    Examples:

    .. literalinclude:: ../../tests/builders/fixtures/system-groovy001.yaml
       :language: yaml
    .. literalinclude:: ../../tests/builders/fixtures/system-groovy002.yaml
       :language: yaml
    """

    root_tag = "hudson.plugins.groovy.SystemGroovy"
    sysgroovy = XML.SubElement(xml_parent, root_tag)
    sysgroovy.append(_groovy_common_scriptSource(data))

    mapping = [("bindings", "bindings", ""), ("class-path", "classpath", "")]
    helpers.convert_mapping_to_xml(sysgroovy, data, mapping, fail_required=True)


def batch(registry, xml_parent, data):
    """yaml: batch
    Execute a batch command.

    :Parameter: the batch command to execute

    Example:

    .. literalinclude:: ../../tests/builders/fixtures/batch.yaml
       :language: yaml
    """
    batch = XML.SubElement(xml_parent, "hudson.tasks.BatchFile")
    XML.SubElement(batch, "command").text = data


def powershell(registry, xml_parent, data):
    """yaml: powershell
    Execute a powershell command.

    Requires the :jenkins-plugins:`Powershell Plugin <powershell>`.

    :Parameter: the powershell command to execute

    Example:

    .. literalinclude:: ../../tests/builders/fixtures/powershell.yaml
       :language: yaml
    """
    ps = XML.SubElement(xml_parent, "hudson.plugins.powershell.PowerShell")
    XML.SubElement(ps, "command").text = data


def msbuild(registry, xml_parent, data):
    """yaml: msbuild
    Build .NET project using msbuild.

    Requires the Jenkins :jenkins-plugins:'MSBuild Plugin <msbuild>`.

    :arg str msbuild-version: which msbuild configured in Jenkins to use
        (default '(Default)')
    :arg str solution-file: location of the solution file to build (required)
    :arg str extra-parameters: extra parameters to pass to msbuild (default '')
    :arg bool pass-build-variables: should build variables be passed
        to msbuild (default true)
    :arg bool continue-on-build-failure: should the build continue if
        msbuild returns an error (default false)
    :arg bool unstable-if-warnings: If set to true and warnings on compilation,
        the build will be unstable (>=1.20) (default false)

    Full Example:

    .. literalinclude:: ../../tests/builders/fixtures/msbuild-full.yaml
       :language: yaml

    Minimal Example:

    .. literalinclude:: ../../tests/builders/fixtures/msbuild-minimal.yaml
       :language: yaml
    """
    msbuilder = XML.SubElement(xml_parent, "hudson.plugins.msbuild.MsBuildBuilder")
    msbuilder.set("plugin", "msbuild")

    mapping = [
        ("msbuild-version", "msBuildName", "(Default)"),
        ("solution-file", "msBuildFile", None),
        ("extra-parameters", "cmdLineArgs", ""),
        ("pass-build-variables", "buildVariablesAsProperties", True),
        ("continue-on-build-failure", "continueOnBuildFailure", False),
        ("unstable-if-warnings", "unstableIfWarnings", False),
    ]
    helpers.convert_mapping_to_xml(msbuilder, data, mapping, fail_required=True)


def create_builders(registry, step):
    dummy_parent = XML.Element("dummy")
    registry.dispatch("builder", dummy_parent, step)
    return list(dummy_parent)


def conditional_step(registry, xml_parent, data):
    """yaml: conditional-step
    Conditionally execute some build steps.

    Requires the Jenkins :jenkins-plugins:`Conditional BuildStep Plugin
    <conditional-buildstep>`.

    Depending on the number of declared steps, a `Conditional step (single)`
    or a `Conditional steps (multiple)` is created in Jenkins.

    :arg str condition-kind: Condition kind that must be verified before the
        steps are executed. Valid values and their additional attributes are
        described in the conditions_ table.
    :arg str on-evaluation-failure: What should be the outcome of the build
        if the evaluation of the condition fails. Possible values are `fail`,
        `mark-unstable`, `run-and-mark-unstable`, `run` and `dont-run`.
        (default 'fail').
    :arg list steps: List of steps to run if the condition is verified. Items
        in the list can be any builder known by Jenkins Job Builder.

    .. _conditions:

    ================== ====================================================
    Condition kind     Description
    ================== ====================================================
    always             Condition is always verified
    never              Condition is never verified
    boolean-expression Run the step if the expression expends to a
                       representation of true

                         :condition-expression: Expression to expand (required)
    build-cause        Run if the current build has a specific cause

                         :cause: The cause why the build was triggered.
                           Following causes are supported -

                           :USER_CAUSE: build was triggered by a manual
                             interaction. (default)
                           :SCM_CAUSE: build was triggered by a SCM change.
                           :TIMER_CAUSE: build was triggered by a timer.
                           :CLI_CAUSE: build was triggered by via CLI interface
                           :REMOTE_CAUSE: build was triggered via remote
                             interface.
                           :UPSTREAM_CAUSE: build was triggered by an upstream
                             project.

                           Following supported if XTrigger plugin installed:

                           :FS_CAUSE: build was triggered by a file system
                             change (FSTrigger Plugin).
                           :URL_CAUSE: build was triggered by a URL change
                             (URLTrigger Plugin)
                           :IVY_CAUSE: build triggered by an Ivy dependency
                             version has change (IvyTrigger Plugin)
                           :SCRIPT_CAUSE: build was triggered by a script
                             (ScriptTrigger Plugin)
                           :BUILDRESULT_CAUSE: build was triggered by a
                             result of another job (BuildResultTrigger Plugin)
                         :exclusive-cause: (bool) There might by multiple
                           causes causing a build to be triggered, with
                           this true, the cause must be the only one
                           causing this build this build to be triggered.
                           (default false)
    day-of-week        Only run on specific days of the week.

                         :day-selector: Days you want the build to run on.
                           Following values are supported -

                           :weekend: Saturday and Sunday (default).
                           :weekday: Monday - Friday.
                           :select-days: Selected days, defined by 'days'
                             below.
                           :days: True for days for which the build should
                             run. Definition needed only for 'select-days'
                             day-selector, at the same level as day-selector.
                             Define the days to run under this.

                             :SUN: Run on Sunday (default false)
                             :MON: Run on Monday (default false)
                             :TUES: Run on Tuesday (default false)
                             :WED: Run on Wednesday (default false)
                             :THURS: Run on Thursday (default false)
                             :FRI: Run on Friday (default false)
                             :SAT: Run on Saturday (default false)
                         :use-build-time: (bool) Use the build time instead of
                           the the time that the condition is evaluated.
                           (default false)
    execution-node     Run only on selected nodes.

                         :nodes: (list) List of nodes to execute on. (required)
    strings-match      Run the step if two strings match

                         :condition-string1: First string (optional)
                         :condition-string2: Second string (optional)
                         :condition-case-insensitive: Case insensitive
                           (default false)
    current-status     Run the build step if the current build status is
                       within the configured range

                         :condition-worst: Accepted values are SUCCESS,
                           UNSTABLE, FAILURE, NOT_BUILD, ABORTED
                           (default SUCCESS)
                         :condition-best: Accepted values are SUCCESS,
                           UNSTABLE, FAILURE, NOT_BUILD, ABORTED
                           (default SUCCESS)

    shell              Run the step if the shell command succeed

                         :condition-command: Shell command to execute
                           (optional)
    windows-shell      Similar to shell, except that commands will be
                       executed by cmd, under Windows

                         :condition-command: Command to execute (optional)
    file-exists        Run the step if a file exists

                         :condition-filename: Check existence of this file
                           (required)
                         :condition-basedir: If condition-filename is
                           relative, it will be considered relative to
                           either `workspace`, `artifact-directory`,
                           or `jenkins-home`. (default 'workspace')
    files-match        Run if one or more files match the selectors.

                         :include-pattern: (list str) List of Includes
                           Patterns. Since the separator in the patterns is
                           hardcoded as ',', any use of ',' would need
                           escaping. (optional)
                         :exclude-pattern: (list str) List of Excludes
                           Patterns. Since the separator in the patterns is
                           hardcoded as ',', any use of ',' would need
                           escaping. (optional)
                         :condition-basedir: Accepted values are `workspace`,
                           `artifact-directory`, or `jenkins-home`.
                           (default 'workspace')
    num-comp           Run if the numerical comparison is true.

                         :lhs: Left Hand Side. Must evaluate to a number.
                           (required)
                         :rhs: Right Hand Side. Must evaluate to a number.
                           (required)
                         :comparator: Accepted values are `less-than`,
                           `greater-than`, `equal`, `not-equal`,
                           `less-than-equal`, `greater-than-equal`.
                           (default 'less-than')
    regex-match        Run if the Expression matches the Label.

                         :regex: The regular expression used to match the label
                           (optional)
                         :label: The label that will be tested by the regular
                           expression. (optional)
    time               Only run during a certain period of the day.

                         :earliest-hour: Starting hour (default "09")
                         :earliest-min: Starting min (default "00")
                         :latest-hour: Ending hour (default "17")
                         :latest-min: Ending min (default "30")
                         :use-build-time: (bool) Use the build time instead of
                           the the time that the condition is evaluated.
                           (default false)
    not                Run the step if the inverse of the condition-operand
                       is true

                         :condition-operand: Condition to evaluate.  Can be
                           any supported conditional-step condition. (required)
    and                Run the step if logical and of all conditional-operands
                       is true

                         :condition-operands: (list) Conditions to evaluate.
                           Can be any supported conditional-step condition.
                           (required)
    or                 Run the step if logical or of all conditional-operands
                       is true

                         :condition-operands: (list) Conditions to evaluate.
                           Can be any supported conditional-step condition.
                           (required)
    ================== ====================================================

    Examples:

    .. literalinclude::
        /../../tests/builders/fixtures/conditional-step-multiple-steps.yaml
       :language: yaml
    .. literalinclude::
        /../../tests/builders/fixtures/conditional-step-success-failure.yaml
       :language: yaml
    .. literalinclude::
        /../../tests/builders/fixtures/conditional-step-not-file-exists.yaml
       :language: yaml
    .. literalinclude::
        /../../tests/builders/fixtures/conditional-step-day-of-week001.yaml
       :language: yaml
    .. literalinclude::
        /../../tests/builders/fixtures/conditional-step-day-of-week003.yaml
       :language: yaml
    .. literalinclude::
        /../../tests/builders/fixtures/conditional-step-time.yaml
       :language: yaml
    .. literalinclude::
        /../../tests/builders/fixtures/conditional-step-regex-match.yaml
       :language: yaml
    .. literalinclude::
        /../../tests/builders/fixtures/conditional-step-or.yaml
       :language: yaml
    .. literalinclude::
        /../../tests/builders/fixtures/conditional-step-and.yaml
       :language: yaml
    """

    def build_condition(cdata, cond_root_tag, condition_tag):
        kind = cdata["condition-kind"]
        ctag = XML.SubElement(cond_root_tag, condition_tag)
        core_prefix = "org.jenkins_ci.plugins.run_condition.core."
        logic_prefix = "org.jenkins_ci.plugins.run_condition.logic."
        if kind == "always":
            ctag.set("class", core_prefix + "AlwaysRun")
        elif kind == "never":
            ctag.set("class", core_prefix + "NeverRun")
        elif kind == "boolean-expression":
            ctag.set("class", core_prefix + "BooleanCondition")
            mapping = [("condition-expression", "token", None)]
            helpers.convert_mapping_to_xml(ctag, cdata, mapping, fail_required=True)
        elif kind == "build-cause":
            ctag.set("class", core_prefix + "CauseCondition")
            cause_list = (
                "USER_CAUSE",
                "SCM_CAUSE",
                "TIMER_CAUSE",
                "CLI_CAUSE",
                "REMOTE_CAUSE",
                "UPSTREAM_CAUSE",
                "FS_CAUSE",
                "URL_CAUSE",
                "IVY_CAUSE",
                "SCRIPT_CAUSE",
                "BUILDRESULT_CAUSE",
            )
            mapping = [
                ("cause", "buildCause", "USER_CAUSE", cause_list),
                ("exclusive-cause", "exclusiveCause", False),
            ]
            helpers.convert_mapping_to_xml(ctag, cdata, mapping, fail_required=True)
        elif kind == "day-of-week":
            ctag.set("class", core_prefix + "DayCondition")
            day_selector_class_prefix = core_prefix + "DayCondition$"
            day_selector_classes = {
                "weekend": day_selector_class_prefix + "Weekend",
                "weekday": day_selector_class_prefix + "Weekday",
                "select-days": day_selector_class_prefix + "SelectDays",
            }
            day_selector = cdata.get("day-selector", "weekend")
            if day_selector not in day_selector_classes:
                raise InvalidAttributeError(
                    "day-selector", day_selector, day_selector_classes
                )
            day_selector_tag = XML.SubElement(ctag, "daySelector")
            day_selector_tag.set("class", day_selector_classes[day_selector])
            if day_selector == "select-days":
                days_tag = XML.SubElement(day_selector_tag, "days")
                day_tag_text = (
                    "org.jenkins__ci.plugins.run__condition." "core.DayCondition_-Day"
                )
                inp_days = cdata.get("days") if cdata.get("days") else {}
                days = ["SUN", "MON", "TUES", "WED", "THURS", "FRI", "SAT"]
                for day_no, day in enumerate(days, 1):
                    day_tag = XML.SubElement(days_tag, day_tag_text)
                    mapping = [("", "day", day_no), (day, "selected", False)]
                    helpers.convert_mapping_to_xml(
                        day_tag, inp_days, mapping, fail_required=True
                    )
            mapping = [("use-build-time", "useBuildTime", False)]
            helpers.convert_mapping_to_xml(ctag, cdata, mapping, fail_required=True)
        elif kind == "execution-node":
            ctag.set("class", core_prefix + "NodeCondition")
            allowed_nodes_tag = XML.SubElement(ctag, "allowedNodes")
            for node in cdata["nodes"]:
                mapping = [("", "string", node)]
                helpers.convert_mapping_to_xml(
                    allowed_nodes_tag, cdata, mapping, fail_required=True
                )
        elif kind == "strings-match":
            ctag.set("class", core_prefix + "StringsMatchCondition")
            mapping = [
                ("condition-string1", "arg1", ""),
                ("condition-string2", "arg2", ""),
                ("condition-case-insensitive", "ignoreCase", False),
            ]
            helpers.convert_mapping_to_xml(ctag, cdata, mapping, fail_required=True)
        elif kind == "current-status":
            ctag.set("class", core_prefix + "StatusCondition")
            wr = XML.SubElement(ctag, "worstResult")
            wr_name = cdata.get("condition-worst", "SUCCESS")
            if wr_name not in hudson_model.THRESHOLDS:
                raise InvalidAttributeError(
                    "condition-worst", wr_name, hudson_model.THRESHOLDS.keys()
                )
            wr_threshold = hudson_model.THRESHOLDS[wr_name]
            mapping = [
                ("name", "name", None),
                ("ordinal", "ordinal", None),
                ("color", "color", "color"),
                ("complete", "completeBuild", None),
            ]
            helpers.convert_mapping_to_xml(
                wr, wr_threshold, mapping, fail_required=True
            )
            br = XML.SubElement(ctag, "bestResult")
            br_name = cdata.get("condition-best", "SUCCESS")
            if br_name not in hudson_model.THRESHOLDS:
                raise InvalidAttributeError(
                    "condition-best", br_name, hudson_model.THRESHOLDS.keys()
                )
            br_threshold = hudson_model.THRESHOLDS[br_name]
            mapping = [
                ("name", "name", None),
                ("ordinal", "ordinal", None),
                ("color", "color", "color"),
                ("complete", "completeBuild", None),
            ]
            helpers.convert_mapping_to_xml(
                br, br_threshold, mapping, fail_required=True
            )
        elif kind == "shell":
            ctag.set(
                "class",
                "org.jenkins_ci.plugins.run_condition.contributed." "ShellCondition",
            )
            mapping = [("condition-command", "command", "")]
            helpers.convert_mapping_to_xml(ctag, cdata, mapping, fail_required=True)
        elif kind == "windows-shell":
            ctag.set(
                "class",
                "org.jenkins_ci.plugins.run_condition.contributed."
                "BatchFileCondition",
            )
            mapping = [("condition-command", "command", "")]
            helpers.convert_mapping_to_xml(ctag, cdata, mapping, fail_required=True)
        elif kind == "file-exists" or kind == "files-match":
            if kind == "file-exists":
                ctag.set("class", core_prefix + "FileExistsCondition")
                mapping = [("condition-filename", "file", None)]
                helpers.convert_mapping_to_xml(ctag, cdata, mapping, fail_required=True)
            else:
                ctag.set("class", core_prefix + "FilesMatchCondition")
                XML.SubElement(ctag, "includes").text = ",".join(
                    cdata.get("include-pattern", "")
                )
                XML.SubElement(ctag, "excludes").text = ",".join(
                    cdata.get("exclude-pattern", "")
                )
            basedir_class_prefix = (
                "org.jenkins_ci.plugins.run_condition." "common.BaseDirectory$"
            )
            basedir_classes = {
                "workspace": basedir_class_prefix + "Workspace",
                "artifact-directory": basedir_class_prefix + "ArtifactsDir",
                "jenkins-home": basedir_class_prefix + "JenkinsHome",
            }
            basedir = cdata.get("condition-basedir", "workspace")
            if basedir not in basedir_classes:
                raise InvalidAttributeError(
                    "condition-basedir", basedir, basedir_classes
                )
            XML.SubElement(ctag, "baseDir").set("class", basedir_classes[basedir])
        elif kind == "num-comp":
            ctag.set("class", core_prefix + "NumericalComparisonCondition")
            mapping = [("lhs", "lhs", None), ("rhs", "rhs", None)]
            helpers.convert_mapping_to_xml(ctag, cdata, mapping, fail_required=True)
            comp_class_prefix = core_prefix + "NumericalComparisonCondition$"
            comp_classes = {
                "less-than": comp_class_prefix + "LessThan",
                "greater-than": comp_class_prefix + "GreaterThan",
                "equal": comp_class_prefix + "EqualTo",
                "not-equal": comp_class_prefix + "NotEqualTo",
                "less-than-equal": comp_class_prefix + "LessThanOrEqualTo",
                "greater-than-equal": comp_class_prefix + "GreaterThanOrEqualTo",
            }
            comp = cdata.get("comparator", "less-than")
            if comp not in comp_classes:
                raise InvalidAttributeError("comparator", comp, comp_classes)
            XML.SubElement(ctag, "comparator").set("class", comp_classes[comp])
        elif kind == "regex-match":
            ctag.set("class", core_prefix + "ExpressionCondition")
            mapping = [("regex", "expression", ""), ("label", "label", "")]
            helpers.convert_mapping_to_xml(ctag, cdata, mapping, fail_required=True)
        elif kind == "time":
            ctag.set("class", core_prefix + "TimeCondition")
            mapping = [
                ("earliest-hour", "earliestHours", "09"),
                ("earliest-min", "earliestMinutes", "00"),
                ("latest-hour", "latestHours", "17"),
                ("latest-min", "latestMinutes", "30"),
                ("use-build-time", "useBuildTime", False),
            ]
            helpers.convert_mapping_to_xml(ctag, cdata, mapping, fail_required=True)
        elif kind == "not":
            ctag.set("class", logic_prefix + "Not")
            try:
                notcondition = cdata["condition-operand"]
            except KeyError:
                raise MissingAttributeError("condition-operand")
            build_condition(notcondition, ctag, "condition")
        elif kind == "and" or "or":
            if kind == "and":
                ctag.set("class", logic_prefix + "And")
            else:
                ctag.set("class", logic_prefix + "Or")
            conditions_tag = XML.SubElement(ctag, "conditions")
            container_tag_text = (
                "org.jenkins__ci.plugins.run__condition." "logic.ConditionContainer"
            )
            try:
                conditions_list = cdata["condition-operands"]
            except KeyError:
                raise MissingAttributeError("condition-operands")
            for condition in conditions_list:
                conditions_container_tag = XML.SubElement(
                    conditions_tag, container_tag_text
                )
                build_condition(condition, conditions_container_tag, "condition")

    def build_step(parent, step):
        for edited_node in create_builders(registry, step):
            if not has_multiple_steps:
                edited_node.set("class", edited_node.tag)
                edited_node.tag = "buildStep"
            parent.append(edited_node)

    cond_builder_tag = (
        "org.jenkinsci.plugins.conditionalbuildstep."
        "singlestep.SingleConditionalBuilder"
    )
    cond_builders_tag = (
        "org.jenkinsci.plugins.conditionalbuildstep." "ConditionalBuilder"
    )
    steps = data["steps"]
    has_multiple_steps = len(steps) > 1

    if has_multiple_steps:
        root_tag = XML.SubElement(xml_parent, cond_builders_tag)
        steps_parent = XML.SubElement(root_tag, "conditionalbuilders")
        condition_tag = "runCondition"
    else:
        root_tag = XML.SubElement(xml_parent, cond_builder_tag)
        steps_parent = root_tag
        condition_tag = "condition"

    build_condition(data, root_tag, condition_tag)
    evaluation_classes_pkg = "org.jenkins_ci.plugins.run_condition"
    evaluation_classes = {
        "fail": evaluation_classes_pkg + ".BuildStepRunner$Fail",
        "mark-unstable": evaluation_classes_pkg + ".BuildStepRunner$Unstable",
        "run-and-mark-unstable": evaluation_classes_pkg
        + ".BuildStepRunner$RunUnstable",
        "run": evaluation_classes_pkg + ".BuildStepRunner$Run",
        "dont-run": evaluation_classes_pkg + ".BuildStepRunner$DontRun",
    }
    evaluation_class = evaluation_classes[data.get("on-evaluation-failure", "fail")]
    XML.SubElement(root_tag, "runner").set("class", evaluation_class)
    for step in steps:
        build_step(steps_parent, step)


def maven_builder(registry, xml_parent, data):
    """yaml: maven-builder
    Execute Maven3 builder

    Allows your build jobs to deploy artifacts automatically to Artifactory.

    Requires the Jenkins `Artifactory Plugin
    <https://www.jfrog.com/confluence/display/RTF/Jenkins+Artifactory+Plug-in>`_.

    :arg str name: Name of maven installation from the configuration (required)
    :arg str pom: Location of pom.xml (default 'pom.xml')
    :arg str goals: Goals to execute (required)
    :arg str maven-opts: Additional options for maven (default '')

    Example:

    .. literalinclude:: /../../tests/builders/fixtures/maven-builder001.yaml
       :language: yaml
    """
    maven = XML.SubElement(xml_parent, "org.jfrog.hudson.maven3.Maven3Builder")

    mapping = [
        ("name", "mavenName", None),
        ("goals", "goals", None),
        ("pom", "rootPom", "pom.xml"),
        ("maven-opts", "mavenOpts", ""),
    ]
    helpers.convert_mapping_to_xml(maven, data, mapping, fail_required=True)


def jira_issue_updater(registry, xml_parent, data):
    """yaml: jenkins-jira-issue-updater
    Updates issues in Atlassian JIRA as part of a Jenkins job.

    Requires the Jenkins :jenkins-plugins:`Jira Issue Updater Plugin
    <jenkins-jira-issue-updater>`.

    :arg str base-url: The base url of the rest API. (default '')
    :arg str username: The Jira username (required)
    :arg str password: The Jira password (required)
    :arg str jql: The JQL used to select the issues to update. (required)
    :arg str workflow: The Name of the workflow action to be executed.
        (default '')
    :arg str comment: The Jira comment to be added. (default '')
    :arg str custom-Id: The Jira custom field to be edited. (default '')
    :arg str custom-value: Jira custom field value. (default '')
    :arg bool fail-if-error: Fail this build if JQL returns error.
        ((default false)
    :arg bool fail-if-no-match: Fail this build if no issues are matched.
        (default false)
    :arg bool fail-if-no-connection: Fail this build if can't connect to Jira.
        (default false)

    Minimal Example:

    .. literalinclude::
        /../../tests/builders/fixtures/jenkins-jira-issue-updater-minimal.yaml
        :language: yaml

    Full Example:

    .. literalinclude::
        /../../tests/builders/fixtures/jenkins-jira-issue-updater-full.yaml
        :language: yaml
    """
    issue_updater = XML.SubElement(
        xml_parent, "info.bluefloyd.jenkins." "IssueUpdatesBuilder"
    )
    issue_updater.set("plugin", "jenkins-jira-issue-updater")

    mapping = [
        ("base-url", "restAPIUrl", ""),
        ("username", "userName", None),
        ("password", "password", None),
        ("jql", "jql", None),
        ("workflow", "workflowActionName", ""),
        ("comment", "comment", ""),
        ("custom-Id", "customFieldId", ""),
        ("custom-value", "customFieldValue", ""),
        ("fail-if-error", "failIfJqlFails", False),
        ("fail-if-no-match", "failIfNoIssuesReturned", False),
        ("fail-if-no-connection", "failIfNoJiraConnection", False),
    ]
    helpers.convert_mapping_to_xml(issue_updater, data, mapping, fail_required=True)


def maven_target(registry, xml_parent, data):
    """yaml: maven-target
    Execute top-level Maven targets.

    Requires the Jenkins :jenkins-plugins:`Config File Provider Plugin
    <config-file-provider>` for the Config File Provider "settings"
    and "global-settings" config.

    :arg str goals: Goals to execute
    :arg str properties: Properties for maven, can have multiples
    :arg str pom: Location of pom.xml (default 'pom.xml')
    :arg bool private-repository: Use private maven repository for this
        job (default false)
    :arg str maven-version: Installation of maven which should be used
        (optional)
    :arg str java-opts: java options for maven, can have multiples,
        must be in quotes (optional)
    :arg str settings: Path to use as user settings.xml
        It is possible to provide a ConfigFileProvider settings file, such as
        see CFP Example below. (optional)
    :arg str settings-type: Type of settings file file|cfp. (default file)
    :arg str global-settings: Path to use as global settings.xml
        It is possible to provide a ConfigFileProvider settings file, such as
        see CFP Example below. (optional)
    :arg str global-settings-type: Type of settings file file|cfp. (default
        file)

    Example:

    .. literalinclude:: /../../tests/builders/fixtures/maven-target-doc.yaml
       :language: yaml

    CFP Example:

    .. literalinclude:: /../../tests/builders/fixtures/maven-target002.yaml
       :language: yaml
    """
    maven = XML.SubElement(xml_parent, "hudson.tasks.Maven")
    XML.SubElement(maven, "targets").text = data["goals"]
    prop_string = "\n".join(data.get("properties", []))
    XML.SubElement(maven, "properties").text = prop_string

    mapping = [
        ("maven-version", "mavenName", None),
        ("pom", "pom", None),
        ("private-repository", "usePrivateRepository", False),
    ]
    helpers.convert_mapping_to_xml(maven, data, mapping, fail_required=False)
    if "java-opts" in data:
        javaoptions = " ".join(data.get("java-opts", []))
        XML.SubElement(maven, "jvmOptions").text = javaoptions
    helpers.config_file_provider_settings(maven, data)


def multijob(registry, xml_parent, data):
    """yaml: multijob
    Define a multijob phase.

    Requires the Jenkins :jenkins-plugins:`Multijob Plugin
    <jenkins-multijob-plugin>`.

    This builder may only be used in
    :py:class:`jenkins_jobs.modules.project_multijob.MultiJob` projects.

    :arg str name: MultiJob phase name
    :arg str condition: when to trigger the other job.
        Can be: 'SUCCESSFUL', 'UNSTABLE', 'COMPLETED', 'FAILURE', 'ALWAYS'.
        (default 'SUCCESSFUL')
    :arg str execution-type: Define how to run jobs in a phase:
        sequentially or parallel.
        Can be: 'PARALLEL', 'SEQUENTIALLY'
        (default 'PARALLEL')

    :arg list projects: list of projects to include in the MultiJob phase

        :Project:
            * **name** (`str`) -- Project name
            * **alias** (`str`) -- Project alias, which will be shown
              in MultiJob Overview. Helpful when working with the same
              project multiple times with different configurations
            * **current-parameters** (`bool`) -- Pass current build
              parameters to the other job (default false)
            * **node-label-name** (`str`) -- Define a list of nodes
              on which the job should be allowed to be executed on.
              Requires NodeLabel Parameter Plugin (optional)
            * **node-label** (`str`) -- Define a label
              of 'Restrict where this project can be run' on the fly.
              Requires NodeLabel Parameter Plugin (optional)
            * **node-parameters** (`bool`) -- Use the same Node for
              the triggered builds that was used for this build. (optional)
            * **git-revision** (`bool`) -- Pass current git-revision
              to the other job (default false)
            * **property-file** (`str`) -- Pass properties from file
              to the other job (optional)
            * **predefined-parameters** (`str`) -- Pass predefined
              parameters to the other job (optional)
            * **abort-all-job** (`bool`) -- Kill allsubs job and the phase job,
              if this subjob is killed (default false)
            * **aggregate-results** (`bool`) -- Aggregate test results.
              (default false)
            * **enable-condition** (`str`) -- Condition to run the
              job in groovy script format (optional)
            * **kill-phase-on** (`str`) -- Stop the phase execution
              on specific job status. Can be 'FAILURE', 'UNSTABLE',
              'NEVER'. (optional)
            * **restrict-matrix-project** (`str`) -- Filter that
              restricts the subset of the combinations that the
              downstream project will run (optional)
            * **retry** (`dict`): Enable retry strategy (optional)
                :retry:
                    * **max-retry** (`int`) -- Max number of retries
                      (default 0)
                    * **strategy-path** (`str`) -- Parsing rules path
                      (required)

    Example:

    .. literalinclude:: /../../tests/builders/fixtures/multibuild.yaml
       :language: yaml
    """
    builder = XML.SubElement(
        xml_parent, "com.tikal.jenkins.plugins.multijob." "MultiJobBuilder"
    )
    conditions_available = ("SUCCESSFUL", "UNSTABLE", "COMPLETED", "FAILURE", "ALWAYS")
    job_execution_type_available = ("PARALLEL", "SEQUENTIALLY")
    mapping = [
        ("name", "phaseName", None),
        ("condition", "continuationCondition", "SUCCESSFUL", conditions_available),
        ("execution-type", "executionType", "PARALLEL", job_execution_type_available),
    ]
    helpers.convert_mapping_to_xml(builder, data, mapping, fail_required=True)

    phaseJobs = XML.SubElement(builder, "phaseJobs")

    kill_status_list = ("FAILURE", "UNSTABLE", "NEVER")

    for project in data.get("projects", []):
        phaseJob = XML.SubElement(
            phaseJobs, "com.tikal.jenkins.plugins." "multijob.PhaseJobsConfig"
        )
        mapping = [
            ("name", "jobName", None),
            # Pass through the current build params
            ("current-parameters", "currParams", False),
        ]
        helpers.convert_mapping_to_xml(phaseJob, project, mapping, fail_required=True)
        # Pass through other params
        if project.get("alias"):
            mapping = [("alias", "jobAlias", None)]
            helpers.convert_mapping_to_xml(
                phaseJob, project, mapping, fail_required=True
            )

        configs = XML.SubElement(phaseJob, "configs")

        nodeLabelName = project.get("node-label-name")
        nodeLabel = project.get("node-label")
        if nodeLabelName and nodeLabel:
            node = XML.SubElement(
                configs,
                "org.jvnet.jenkins.plugins.nodelabelparameter."
                "parameterizedtrigger.NodeLabelBuildParameter",
            )
            mapping = [("", "name", nodeLabelName), ("", "nodeLabel", nodeLabel)]
            helpers.convert_mapping_to_xml(node, project, mapping, fail_required=True)

        # Node parameter
        if project.get("node-parameters", False):
            XML.SubElement(
                configs, "hudson.plugins.parameterizedtrigger." "NodeParameters"
            )

        # Git Revision
        if project.get("git-revision", False):
            param = XML.SubElement(
                configs, "hudson.plugins.git." "GitRevisionBuildParameters"
            )
            mapping = [("", "combineQueuedCommits", False)]
            helpers.convert_mapping_to_xml(param, project, mapping, fail_required=True)

        # Properties File
        properties_file = project.get("property-file", False)
        if properties_file:
            param = XML.SubElement(
                configs, "hudson.plugins.parameterizedtrigger." "FileBuildParameters"
            )
            mapping = [
                ("", "propertiesFile", properties_file),
                ("", "failTriggerOnMissing", True),
            ]
            helpers.convert_mapping_to_xml(param, project, mapping, fail_required=True)

        # Predefined Parameters
        predefined_parameters = project.get("predefined-parameters", False)
        if predefined_parameters:
            param = XML.SubElement(
                configs,
                "hudson.plugins.parameterizedtrigger." "PredefinedBuildParameters",
            )
            mapping = [("", "properties", predefined_parameters)]
            helpers.convert_mapping_to_xml(param, project, mapping, fail_required=True)

        mapping = [
            ("abort-all-job", "abortAllJob", False),
            ("aggregate-results", "aggregatedTestResults", False),
        ]
        helpers.convert_mapping_to_xml(phaseJob, project, mapping, fail_required=True)

        # Retry job
        retry = project.get("retry", False)
        if retry:
            max_retry = retry.get("max-retry", 0)
            mapping = [
                ("strategy-path", "parsingRulesPath", None),
                ("", "maxRetries", int(max_retry)),
                ("", "enableRetryStrategy", True),
            ]
            helpers.convert_mapping_to_xml(phaseJob, retry, mapping, fail_required=True)
        else:
            XML.SubElement(phaseJob, "enableRetryStrategy").text = "false"

        # Restrict matrix jobs to a subset
        if project.get("restrict-matrix-project") is not None:
            subset = XML.SubElement(
                configs,
                "hudson.plugins.parameterizedtrigger."
                "matrix.MatrixSubsetBuildParameters",
            )
            mapping = [("restrict-matrix-project", "filter", None)]
            helpers.convert_mapping_to_xml(subset, project, mapping, fail_required=True)

        # Enable Condition
        enable_condition = project.get("enable-condition")
        if enable_condition is not None:
            mapping = [
                ("", "enableCondition", True),
                ("", "condition", enable_condition),
            ]
            helpers.convert_mapping_to_xml(
                phaseJob, project, mapping, fail_required=True
            )

        # Kill phase on job status
        kill_status = project.get("kill-phase-on")
        if kill_status is not None:
            kill_status = kill_status.upper()
            mapping = [
                ("", "killPhaseOnJobResultCondition", kill_status, kill_status_list)
            ]
            helpers.convert_mapping_to_xml(
                phaseJob, project, mapping, fail_required=True
            )


def config_file_provider(registry, xml_parent, data):
    """yaml: config-file-provider
    Provide configuration files (i.e., settings.xml for maven etc.)
    which will be copied to the job's workspace.

    Requires the Jenkins :jenkins-plugins:`Config File Provider Plugin
    <config-file-provider>`.

    :arg list files: List of managed config files made up of three
        parameters

        :files:
            * **file-id** (`str`) -- The identifier for the managed config
              file
            * **target** (`str`) -- Define where the file should be created
              (default '')
            * **variable** (`str`) -- Define an environment variable to be
              used (default '')
            * **replace-tokens** (`bool`) -- Replace tokens in config file. For
              example "password: ${PYPI_JENKINS_PASS}" will be replaced with
              the global variable configured in Jenkins.

    Full Example:

    .. literalinclude::
        ../../tests/builders/fixtures/config-file-provider-full.yaml
       :language: yaml

    Minimal Example:

    .. literalinclude::
        ../../tests/builders/fixtures/config-file-provider-minimal.yaml
       :language: yaml
    """
    cfp = XML.SubElement(
        xml_parent, "org.jenkinsci.plugins.configfiles.builder." "ConfigFileBuildStep"
    )
    cfp.set("plugin", "config-file-provider")
    helpers.config_file_provider_builder(cfp, data)


def grails(registry, xml_parent, data):
    """yaml: grails
    Execute a grails build step.

    Requires the :jenkins-wiki:`Jenkins Grails Plugin <Grails+Plugin>`.

    :arg bool use-wrapper: Use a grails wrapper (default false)
    :arg str name: Select a grails installation to use (default '(Default)')
    :arg bool force-upgrade: Run 'grails upgrade --non-interactive'
        first (default false)
    :arg bool non-interactive: append --non-interactive to all build targets
        (default false)
    :arg str targets: Specify target(s) to run separated by spaces (required)
    :arg str server-port: Specify a value for the server.port system
        property (default '')
    :arg str work-dir: Specify a value for the grails.work.dir system
        property (default '')
    :arg str project-dir: Specify a value for the grails.project.work.dir
        system property (default '')
    :arg str base-dir: Specify a path to the root of the Grails
        project (default '')
    :arg str properties: Additional system properties to set (default '')
    :arg bool plain-output: append --plain-output to all build targets
        (default false)
    :arg bool stack-trace: append --stack-trace to all build targets
        (default false)
    :arg bool verbose: append --verbose to all build targets
        (default false)
    :arg bool refresh-dependencies: append --refresh-dependencies to all
        build targets (default false)

    Full Example:

    .. literalinclude:: ../../tests/builders/fixtures/grails-full.yaml
       :language: yaml

    Minimal Example:

    .. literalinclude:: ../../tests/builders/fixtures/grails-minimal.yaml
       :language: yaml
    """
    grails = XML.SubElement(xml_parent, "com.g2one.hudson.grails." "GrailsBuilder")
    grails.set("plugin", "grails")

    mappings = [
        ("targets", "targets", None),
        ("name", "name", "(Default)"),
        ("work-dir", "grailsWorkDir", ""),
        ("project-dir", "projectWorkDir", ""),
        ("base-dir", "projectBaseDir", ""),
        ("server-port", "serverPort", ""),
        ("properties", "properties", ""),
        ("force-upgrade", "forceUpgrade", False),
        ("non-interactive", "nonInteractive", False),
        ("use-wrapper", "useWrapper", False),
        ("plain-output", "plainOutput", False),
        ("stack-trace", "stackTrace", False),
        ("verbose", "verbose", False),
        ("refresh-dependencies", "refreshDependencies", False),
    ]
    helpers.convert_mapping_to_xml(grails, data, mappings, fail_required=True)


def sbt(registry, xml_parent, data):
    """yaml: sbt
    Execute a sbt build step.

    Requires the Jenkins :jenkins-plugins:`Sbt Plugin <sbt>`.

    :arg str name: Select a sbt installation to use. If no name is
        provided, the first in the list of defined SBT builders will be
        used. (default to first in list)
    :arg str jvm-flags: Parameters to pass to the JVM (default '')
    :arg str actions: Select the sbt tasks to execute (default '')
    :arg str sbt-flags: Add flags to SBT launcher
        (default '-Dsbt.log.noformat=true')
    :arg str subdir-path: Path relative to workspace to run sbt in
        (default '')

    Example:

    .. literalinclude:: ../../tests/builders/fixtures/sbt.yaml
       :language: yaml
    """
    sbt = XML.SubElement(xml_parent, "org.jvnet.hudson.plugins." "SbtPluginBuilder")
    mappings = [
        ("name", "name", ""),
        ("jvm-flags", "jvmFlags", ""),
        ("sbt-flags", "sbtFlags", "-Dsbt.log.noformat=true"),
        ("actions", "actions", ""),
        ("subdir-path", "subdirPath", ""),
    ]
    helpers.convert_mapping_to_xml(sbt, data, mappings, fail_required=True)


def critical_block_start(registry, xml_parent, data):
    """yaml: critical-block-start
    Designate the start of a critical block. Must be used in conjunction with
    critical-block-end.

    Must also add a build wrapper (exclusion), specifying the resources that
    control the critical block. Otherwise, this will have no effect.

    Requires the Jenkins :jenkins-plugins:`Exclusion Plugin <Exclusion>`.

    Example:

    .. literalinclude::
        ../../tests/yamlparser/fixtures/critical_block_complete001.yaml
       :language: yaml
    """
    cbs = XML.SubElement(
        xml_parent, "org.jvnet.hudson.plugins.exclusion.CriticalBlockStart"
    )
    cbs.set("plugin", "Exclusion")


def critical_block_end(registry, xml_parent, data):
    """yaml: critical-block-end
    Designate the end of a critical block. Must be used in conjunction with
    critical-block-start.

    Must also add a build wrapper (exclusion), specifying the resources that
    control the critical block. Otherwise, this will have no effect.

    Requires the Jenkins :jenkins-plugins:`Exclusion Plugin <Exclusion>`.

    Example:

    .. literalinclude::
        ../../tests/yamlparser/fixtures/critical_block_complete001.yaml
       :language: yaml
    """
    cbs = XML.SubElement(
        xml_parent, "org.jvnet.hudson.plugins.exclusion.CriticalBlockEnd"
    )
    cbs.set("plugin", "Exclusion")


def publish_over_ssh(registry, xml_parent, data):
    """yaml: publish-over-ssh
    Send files or execute commands over SSH.

    Requires the Jenkins :jenkins-plugins:`Publish over SSH Plugin
    <publish-over-ssh>`.

    :arg str site: name of the ssh site
    :arg str target: destination directory
    :arg bool target-is-date-format: whether target is a date format. If true,
        raw text should be quoted (default false)
    :arg bool clean-remote: should the remote directory be deleted before
        transferring files (default false)
    :arg str source: source path specifier
    :arg str command: a command to execute on the remote server (optional)
    :arg int timeout: timeout in milliseconds for the Exec command (optional)
    :arg bool use-pty: run the exec command in pseudo TTY (default false)
    :arg str excludes: excluded file pattern (optional)
    :arg str remove-prefix: prefix to remove from uploaded file paths
        (optional)
    :arg bool fail-on-error: fail the build if an error occurs (default false)

    Example:

    .. literalinclude:: /../../tests/builders/fixtures/publish-over-ssh.yaml
       :language: yaml
    """
    ssh(registry, xml_parent, data)


def publish_over_cifs(registry, xml_parent, data):
    """yaml: publish-over-cifs
    Upload files via CIFS.

    Requires the Jenkins :jenkins-plugins:`Publish over CIFS Plugin
    <publish-over-cifs>`.

    :arg str site: name of the ssh site
    :arg str target: destination directory
    :arg bool target-is-date-format: whether target is a date format. If true,
        raw text should be quoted (default false)
    :arg bool clean-remote: should the remote directory be deleted before
        transferring files (default false)
    :arg str source: source path specifier
    :arg str excludes: excluded file pattern (optional)
    :arg str remove-prefix: prefix to remove from uploaded file paths
        (optional)
    :arg bool fail-on-error: fail the build if an error occurs (default false)
    :arg bool flatten: only create files on the server, don't create
        directories (default false)

    Example:

    .. literalinclude:: /../../tests/builders/fixtures/publish-over-cifs.yaml
       :language: yaml
    """
    cifs(registry, xml_parent, data)


def saltstack(parser, xml_parent, data):
    """yaml: saltstack

    Send a message to Salt API.

    Requires the Jenkins :jenkins-plugins:`saltstack plugin <saltstack>`.

    :arg str servername: Salt master server name (required)
    :arg str authtype: Authentication type ('pam' or 'ldap', default 'pam')
    :arg str credentials: Credentials ID for which to authenticate to Salt
        master (required)
    :arg str target: Target minions (default '')
    :arg str targettype: Target type ('glob', 'pcre', 'list', 'grain',
        'pillar', 'nodegroup', 'range', or 'compound', default 'glob')
    :arg str function: Function to execute (default '')
    :arg str arguments: Salt function arguments (default '')
    :arg str kwarguments: Salt keyword arguments (default '')
    :arg bool saveoutput: Save Salt return data into environment variable
        (default false)
    :arg str clientinterface: Client interface type ('local', 'local-batch',
        or 'runner', default 'local')
    :arg bool wait: Wait for completion of command (default false)
    :arg str polltime: Number of seconds to wait before polling job completion
        status (default '')
    :arg str batchsize: Salt batch size, absolute value or %-age (default 100%)
    :arg str mods: Mods to runner (default '')
    :arg bool setpillardata: Set Pillar data (default false)
    :arg str pillarkey: Pillar key (default '')
    :arg str pillarvalue: Pillar value (default '')

    Minimal Example:

    .. literalinclude:: ../../tests/builders/fixtures/saltstack-minimal.yaml
       :language: yaml

    Full Example:

    .. literalinclude:: ../../tests/builders/fixtures/saltstack-full.yaml
       :language: yaml
    """
    saltstack = XML.SubElement(xml_parent, "com.waytta.SaltAPIBuilder")

    supported_auth_types = ["pam", "ldap"]
    supported_target_types = [
        "glob",
        "pcre",
        "list",
        "grain",
        "pillar",
        "nodegroup",
        "range",
        "compound",
    ]
    supported_client_interfaces = ["local", "local-batch", "runner"]

    mapping = [
        ("servername", "servername", None),
        ("credentials", "credentialsId", None),
        ("authtype", "authtype", "pam", supported_auth_types),
        ("target", "target", ""),
        ("targettype", "targettype", "glob", supported_target_types),
        ("clientinterface", "clientInterface", "local", supported_client_interfaces),
        ("function", "function", ""),
        ("arguments", "arguments", ""),
        ("kwarguments", "kwarguments", ""),
        ("setpillardata", "usePillar", False),
        ("pillarkey", "pillarkey", ""),
        ("pillarvalue", "pillarvalue", ""),
        ("wait", "blockbuild", False),
        ("polltime", "jobPollTime", ""),
        ("batchsize", "batchSize", "100%"),
        ("mods", "mods", ""),
        ("saveoutput", "saveEnvVar", False),
    ]

    helpers.convert_mapping_to_xml(saltstack, data, mapping, fail_required=True)

    clientInterface = data.get("clientinterface", "local")
    blockbuild = str(data.get("wait", False)).lower()
    jobPollTime = str(data.get("polltime", ""))
    batchSize = data.get("batchsize", "100%")
    mods = data.get("mods", "")
    usePillar = str(data.get("setpillardata", False)).lower()

    # Build the clientInterfaces structure, based on the
    # clientinterface setting
    clientInterfaces = XML.SubElement(saltstack, "clientInterfaces")
    XML.SubElement(clientInterfaces, "nullObject").text = "false"

    ci_attrib = {
        "class": "org.apache.commons.collections.map.ListOrderedMap",
        "serialization": "custom",
    }
    properties = XML.SubElement(clientInterfaces, "properties", ci_attrib)

    lomElement = "org.apache.commons.collections.map.ListOrderedMap"
    listOrderedMap = XML.SubElement(properties, lomElement)

    default = XML.SubElement(listOrderedMap, "default")
    ordered_map = XML.SubElement(listOrderedMap, "map")

    insertOrder = XML.SubElement(default, "insertOrder")

    ci_config = []
    if clientInterface == "local":
        ci_config = [
            ("blockbuild", blockbuild),
            ("jobPollTime", jobPollTime),
            ("clientInterface", clientInterface),
        ]

    elif clientInterface == "local-batch":
        ci_config = [("batchSize", batchSize), ("clientInterface", clientInterface)]

    elif clientInterface == "runner":
        ci_config = [("mods", mods), ("clientInterface", clientInterface)]

        if usePillar == "true":
            ci_config.append(("usePillar", usePillar))

            pillar_cfg = [
                ("pillarkey", data.get("pillarkey")),
                ("pillarvalue", data.get("pillarvalue")),
            ]

    for emt, value in ci_config:
        XML.SubElement(insertOrder, "string").text = emt
        entry = XML.SubElement(ordered_map, "entry")
        XML.SubElement(entry, "string").text = emt

        # Special handling when usePillar == true, requires additional
        # structure in the builder XML
        if emt != "usePillar":
            XML.SubElement(entry, "string").text = value
        else:
            jsonobj = XML.SubElement(entry, "net.sf.json.JSONObject")
            XML.SubElement(jsonobj, "nullObject").text = "false"

            pillarProps = XML.SubElement(jsonobj, "properties", ci_attrib)
            XML.SubElement(pillarProps, "unserializable-parents")

            pillarLom = XML.SubElement(pillarProps, lomElement)

            pillarDefault = XML.SubElement(pillarLom, "default")
            pillarMap = XML.SubElement(pillarLom, "map")
            pillarInsertOrder = XML.SubElement(pillarDefault, "insertOrder")

            for pemt, value in pillar_cfg:
                XML.SubElement(pillarInsertOrder, "string").text = pemt
                pillarEntry = XML.SubElement(pillarMap, "entry")
                XML.SubElement(pillarEntry, "string").text = pemt
                XML.SubElement(pillarEntry, "string").text = value


class Builders(jenkins_jobs.modules.base.Base):
    sequence = 60

    component_type = "builder"
    component_list_type = "builders"

    def gen_xml(self, xml_parent, data):

        for alias in ["prebuilders", "builders", "postbuilders"]:
            if alias in data:
                builders = XML.SubElement(xml_parent, alias)
                for builder in data[alias]:
                    self.registry.dispatch("builder", builders, builder)

        # Make sure freestyle projects always have a <builders> entry
        # or Jenkins v1.472 (at least) will NPE.
        project_type = data.get("project-type", "freestyle")
        if project_type in ("freestyle", "matrix") and "builders" not in data:
            XML.SubElement(xml_parent, "builders")


def shining_panda(registry, xml_parent, data):
    """yaml: shining-panda
    Execute a command inside various python environments.

    Requires the Jenkins :jenkins-plugins:`ShiningPanda plugin
    <shiningpanda>`.

    :arg str build-environment: Building environment to set up (required).

        :build-environment values:
            * **python**: Use a python installation configured in Jenkins.
            * **custom**: Use a manually installed python.
            * **virtualenv**: Create a virtualenv

    For the **python** environment

    :arg str python-version: Name of the python installation to use.
        Must match one of the configured installations on server
        configuration (default 'System-CPython-2.7')

    For the **custom** environment:

    :arg str home: path to the home folder of the custom installation
        (required)

    For the **virtualenv** environment:

    :arg str python-version: Name of the python installation to use.
        Must match one of the configured installations on server
        configuration (default 'System-CPython-2.7')
    :arg str name: Name of this virtualenv. Two virtualenv builders with
        the same name will use the same virtualenv installation (optional)
    :arg bool clear: If true, delete and recreate virtualenv on each build.
        (default false)
    :arg bool use-distribute: if true use distribute, if false use
        setuptools. (default true)
    :arg bool system-site-packages: if true, give access to the global
        site-packages directory to the virtualenv. (default false)

    Common to all environments:

    :arg str nature: Nature of the command field. (default shell)

        :nature values:
            * **shell**: execute the Command contents with default shell
            * **xshell**: like **shell** but performs platform conversion
              first
            * **python**: execute the Command contents with the Python
              executable

    :arg str command: The command to execute
    :arg bool ignore-exit-code: mark the build as failure if any of the
        commands exits with a non-zero exit code. (default false)

    Examples:

    .. literalinclude::
        /../../tests/builders/fixtures/shining-panda-pythonenv.yaml
       :language: yaml

    .. literalinclude::
        /../../tests/builders/fixtures/shining-panda-customenv.yaml
       :language: yaml

    .. literalinclude::
        /../../tests/builders/fixtures/shining-panda-virtualenv.yaml
       :language: yaml
    """

    pluginelementpart = "jenkins.plugins.shiningpanda.builders."
    buildenvdict = {
        "custom": "CustomPythonBuilder",
        "virtualenv": "VirtualenvBuilder",
        "python": "PythonBuilder",
    }
    envs = buildenvdict.keys()

    try:
        buildenv = data["build-environment"]
    except KeyError:
        raise MissingAttributeError("build-environment")

    if buildenv not in envs:
        raise InvalidAttributeError("build-environment", buildenv, envs)

    t = XML.SubElement(xml_parent, "%s%s" % (pluginelementpart, buildenvdict[buildenv]))

    if buildenv in ("python", "virtualenv"):
        python_mapping = [("python-version", "pythonName", "System-CPython-2.7")]
        helpers.convert_mapping_to_xml(t, data, python_mapping, fail_required=True)

    if buildenv in "custom":
        custom_mapping = [("home", "home", None)]
        helpers.convert_mapping_to_xml(t, data, custom_mapping, fail_required=True)
    if buildenv in "virtualenv":
        virtualenv_mapping = [
            ("name", "home", ""),
            ("clear", "clear", False),
            ("use-distribute", "useDistribute", False),
            ("system-site-packages", "systemSitePackages", False),
        ]
        helpers.convert_mapping_to_xml(t, data, virtualenv_mapping, fail_required=True)

    # Common arguments
    naturelist = ["shell", "xshell", "python"]
    mapping = [
        ("nature", "nature", "shell", naturelist),
        ("command", "command", ""),
        ("ignore-exit-code", "ignoreExitCode", False),
    ]
    helpers.convert_mapping_to_xml(t, data, mapping, fail_required=True)


def tox(registry, xml_parent, data):
    """yaml: tox
    Use tox to build a multi-configuration project.

    Requires the Jenkins :jenkins-plugins:`ShiningPanda plugin
    <shiningpanda>`.

    :arg str ini: The TOX configuration file path (default tox.ini)
    :arg bool recreate: If true, create a new environment each time (default
        false)
    :arg str toxenv-pattern: The pattern used to build the TOXENV environment
        variable. (optional)

    Example:

    .. literalinclude:: /../../tests/builders/fixtures/tox001.yaml
       :language: yaml
    """
    pluginelement = "jenkins.plugins.shiningpanda.builders.ToxBuilder"
    t = XML.SubElement(xml_parent, pluginelement)
    mappings = [("ini", "toxIni", "tox.ini"), ("recreate", "recreate", False)]
    helpers.convert_mapping_to_xml(t, data, mappings, fail_required=True)
    pattern = data.get("toxenv-pattern")
    if pattern:
        XML.SubElement(t, "toxenvPattern").text = pattern


def managed_script(registry, xml_parent, data):
    """yaml: managed-script
    This step allows you to reference and execute a centrally managed
    script within your build.

    Requires the Jenkins :jenkins-plugins:`Managed Scripts Plugin
    <managed-scripts>`.

    :arg str script-id: Id of script to execute (required)
    :arg str type: Type of managed file (default script)

        :type values:
            * **batch**: Execute managed windows batch
            * **script**: Execute managed script

    :arg list args: Arguments to be passed to referenced script

    Example:

    .. literalinclude:: /../../tests/builders/fixtures/managed-script.yaml
       :language: yaml

    .. literalinclude:: /../../tests/builders/fixtures/managed-winbatch.yaml
       :language: yaml
    """
    step_type = data.get("type", "script").lower()
    if step_type == "script":
        step = "ScriptBuildStep"
        script_tag = "buildStepId"
    elif step_type == "batch":
        step = "WinBatchBuildStep"
        script_tag = "command"
    else:
        raise InvalidAttributeError("type", step_type, ["script", "batch"])
    ms = XML.SubElement(xml_parent, "org.jenkinsci.plugins.managedscripts." + step)
    mapping = [("script-id", script_tag, None)]
    helpers.convert_mapping_to_xml(ms, data, mapping, fail_required=True)
    args = XML.SubElement(ms, "buildStepArgs")
    for arg in data.get("args", []):
        XML.SubElement(args, "string").text = arg


def cmake(registry, xml_parent, data):
    """yaml: cmake
    Execute a CMake target.

    Requires the Jenkins :jenkins-plugins:`CMake Plugin <cmakebuilder>`.

    This builder is compatible with both versions 2.x and 1.x of the
    plugin. When specifying paramenters from both versions only the ones from
    the installed version in Jenkins will be used, and the rest will be
    ignored.

    :arg str source-dir: the source code directory relative to the workspace
        directory. (required)
    :arg str build-type: Sets the "build type" option for CMake (default
        "Debug").
    :arg str preload-script: Path to a CMake preload script file. (optional)
    :arg str other-arguments: Other arguments to be added to the CMake
        call. (optional)
    :arg bool clean-build-dir: If true, delete the build directory before each
        build (default false).

    :arg list generator: The makefile generator (default "Unix Makefiles").

        :type Possible generators:
            * **Borland Makefiles**
            * **CodeBlocks - MinGW Makefiles**
            * **CodeBlocks - Unix Makefiles**
            * **Eclipse CDT4 - MinGW Makefiles**
            * **Eclipse CDT4 - NMake Makefiles**
            * **Eclipse CDT4 - Unix Makefiles**
            * **MSYS Makefiles**
            * **MinGW Makefiles**
            * **NMake Makefiles**
            * **Unix Makefiles**
            * **Visual Studio 6**
            * **Visual Studio 7 .NET 2003**
            * **Visual Studio 8 2005**
            * **Visual Studio 8 2005 Win64**
            * **Visual Studio 9 2008**
            * **Visual Studio 9 2008 Win64**
            * **Watcom WMake**

    :Version 2.x: Parameters that available only to versions 2.x of the plugin

        * **working-dir** (`str`): The directory where the project will be
          built in. Relative to the workspace directory. (optional)
        * **installation-name** (`str`): The CMake installation to be used on
          this builder. Use one defined in your Jenkins global configuration
          page (default "InSearchPath").
        * **build-tool-invocations** (`list`): list of build tool invocations
          that will happen during the build:

            :Build tool invocations:
                * **use-cmake** (`str`) -- Whether to run the actual build tool
                    directly (by expanding ``$CMAKE_BUILD_TOOL``) or to have
                    cmake run the build tool (by invoking ``cmake --build
                    <dir>``) (default false).
                * **arguments** (`str`) -- Specify arguments to pass to the
                    build tool or cmake (separated by spaces). Arguments may
                    contain spaces if they are enclosed in double
                    quotes. (optional)
                * **environment-variables** (`str`) -- Specify extra
                    environment variables to pass to the build tool as
                    key-value pairs here. Each entry must be on its own line,
                    for example:

                      ``DESTDIR=${WORKSPACE}/artifacts/dir``

                      ``KEY=VALUE``

    :Version 1.x: Parameters available only to versions 1.x of the plugin

        * **build-dir** (`str`): The directory where the project will be built
          in.  Relative to the workspace directory. (optional)
        * **install-dir** (`str`): The directory where the project will be
          installed in, relative to the workspace directory. (optional)
        * **build-type** (`list`): Sets the "build type" option. A custom type
          different than the default ones specified on the CMake plugin can
          also be set, which will be automatically used in the "Other Build
          Type" option of the plugin. (default "Debug")

            :Default types present in the CMake plugin:
                * **Debug**
                * **Release**
                * **RelWithDebInfo**
                * **MinSizeRel**

        * **make-command** (`str`): The make command (default "make").
        * **install-command** (`arg`): The install command (default "make
          install").
        * **custom-cmake-path** (`str`): Path to cmake executable. (optional)
        * **clean-install-dir** (`bool`): If true, delete the install dir
          before each build (default false).

    Example (Versions 2.x):

    .. literalinclude::
        ../../tests/builders/fixtures/cmake/version-2.0/complete-2.x.yaml
       :language: yaml

    Example (Versions 1.x):

    .. literalinclude::
        ../../tests/builders/fixtures/cmake/version-1.10/complete-1.x.yaml
       :language: yaml
    """

    BUILD_TYPES = ["Debug", "Release", "RelWithDebInfo", "MinSizeRel"]
    cmake = XML.SubElement(xml_parent, "hudson.plugins.cmake.CmakeBuilder")

    mapping = [
        ("source-dir", "sourceDir", None),  # Required parameter
        ("generator", "generator", "Unix Makefiles"),
        ("clean-build-dir", "cleanBuild", False),
    ]
    helpers.convert_mapping_to_xml(cmake, data, mapping, fail_required=True)

    info = registry.get_plugin_info("CMake plugin")
    # Note: Assume latest version of plugin is preferred config format
    version = pkg_resources.parse_version(info.get("version", str(sys.maxsize)))

    if version >= pkg_resources.parse_version("2.0"):
        mapping_20 = [
            ("preload-script", "preloadScript", None),  # Optional parameter
            ("working-dir", "workingDir", ""),
            ("build-type", "buildType", "Debug"),
            ("installation-name", "installationName", "InSearchPath"),
            ("other-arguments", "toolArgs", ""),
        ]
        helpers.convert_mapping_to_xml(cmake, data, mapping_20, fail_required=False)

        tool_steps = XML.SubElement(cmake, "toolSteps")

        for step_data in data.get("build-tool-invocations", []):
            step = XML.SubElement(tool_steps, "hudson.plugins.cmake.BuildToolStep")
            step_mapping = [
                ("use-cmake", "withCmake", False),
                ("arguments", "args", ""),
                ("environment-variables", "vars", ""),
            ]
            helpers.convert_mapping_to_xml(
                step, step_data, step_mapping, fail_required=True
            )

    else:
        mapping_10 = [
            ("preload-script", "preloadScript", ""),
            ("build-dir", "buildDir", ""),
            ("install-dir", "installDir", ""),
            ("make-command", "makeCommand", "make"),
            ("install-command", "installCommand", "make install"),
            ("other-arguments", "cmakeArgs", ""),
            ("custom-cmake-path", "projectCmakePath", ""),
            ("clean-install-dir", "cleanInstallDir", False),
        ]
        helpers.convert_mapping_to_xml(cmake, data, mapping_10, fail_required=True)

        # The options buildType and otherBuildType work together on the CMake
        # plugin:
        #  * If the passed value is one of the predefined values, set buildType
        #    to it and otherBuildType to blank;
        #  * Otherwise, set otherBuildType to the value, and buildType to
        #    "Debug". The CMake plugin will ignore the buildType option.
        #
        # It is strange and confusing that the plugin author chose to do
        # something like that instead of simply passing a string "buildType"
        # option, so this was done to simplify it for the JJB user.
        build_type = XML.SubElement(cmake, "buildType")
        build_type.text = data.get("build-type", BUILD_TYPES[0])
        other_build_type = XML.SubElement(cmake, "otherBuildType")

        if build_type.text not in BUILD_TYPES:
            other_build_type.text = build_type.text
            build_type.text = BUILD_TYPES[0]
        else:
            other_build_type.text = ""

        # The plugin generates this tag, but there doesn't seem to be anything
        # that can be configurable by it. Let's keep it to maintain
        # compatibility:
        XML.SubElement(cmake, "builderImpl")


def dsl(registry, xml_parent, data):
    r"""yaml: dsl
    Process Job DSL

    Requires the Jenkins :jenkins-plugins:`Job DSL plugin <job-dsl>`.

    :arg str script-text: dsl script which is Groovy code (Required if targets
        is not specified)
    :arg str targets: Newline separated list of DSL scripts, located in the
        Workspace. Can use wildcards like 'jobs/\*/\*/\*.groovy' (Required
        if script-text is not specified)
    :arg str ignore-existing: Ignore previously generated jobs and views
    :arg str removed-job-action: Specifies what to do when a previously
        generated job is not referenced anymore, can be 'IGNORE', 'DISABLE',
        or 'DELETE' (default 'IGNORE')
    :arg str removed-view-action: Specifies what to do when a previously
        generated view is not referenced anymore, can be 'IGNORE' or 'DELETE'.
        (default 'IGNORE')
    :arg str lookup-strategy: Determines how relative job names in DSL
        scripts are interpreted, can be 'JENKINS_ROOT' or 'SEED_JOB'.
        (default 'JENKINS_ROOT')
    :arg str additional-classpath: Newline separated list of additional
        classpath entries for the Job DSL scripts. All entries must be
        relative to the workspace root, e.g. build/classes/main. (optional)

    Example:

    .. literalinclude:: /../../tests/builders/fixtures/dsl001.yaml
       :language: yaml
    .. literalinclude:: /../../tests/builders/fixtures/dsl002.yaml
       :language: yaml

    """

    dsl = XML.SubElement(xml_parent, "javaposse.jobdsl.plugin.ExecuteDslScripts")

    if "target" in data:
        if "targets" not in data:
            logger.warning(
                "Converting from old format of 'target' to new "
                "name 'targets', please update your job "
                "definitions."
            )
            data["targets"] = data["target"]
        else:
            logger.warning(
                "Ignoring old argument 'target' in favour of new "
                "format argument 'targets', please remove old "
                "format."
            )

    if data.get("script-text"):
        XML.SubElement(dsl, "scriptText").text = data.get("script-text")
        XML.SubElement(dsl, "usingScriptText").text = "true"
    elif data.get("targets"):
        XML.SubElement(dsl, "targets").text = data.get("targets")
        XML.SubElement(dsl, "usingScriptText").text = "false"
    else:
        raise MissingAttributeError(["script-text", "target"])

    XML.SubElement(dsl, "ignoreExisting").text = str(
        data.get("ignore-existing", False)
    ).lower()

    supportedJobActions = ["IGNORE", "DISABLE", "DELETE"]
    removedJobAction = data.get("removed-job-action", supportedJobActions[0])
    if removedJobAction not in supportedJobActions:
        raise InvalidAttributeError(
            "removed-job-action", removedJobAction, supportedJobActions
        )
    XML.SubElement(dsl, "removedJobAction").text = removedJobAction

    supportedViewActions = ["IGNORE", "DELETE"]
    removedViewAction = data.get("removed-view-action", supportedViewActions[0])
    if removedViewAction not in supportedViewActions:
        raise InvalidAttributeError(
            "removed-view-action", removedViewAction, supportedViewActions
        )
    XML.SubElement(dsl, "removedViewAction").text = removedViewAction

    supportedLookupActions = ["JENKINS_ROOT", "SEED_JOB"]
    lookupStrategy = data.get("lookup-strategy", supportedLookupActions[0])
    if lookupStrategy not in supportedLookupActions:
        raise InvalidAttributeError(
            "lookup-strategy", lookupStrategy, supportedLookupActions
        )
    XML.SubElement(dsl, "lookupStrategy").text = lookupStrategy

    XML.SubElement(dsl, "additionalClasspath").text = data.get("additional-classpath")


def github_notifier(registry, xml_parent, data):
    """yaml: github-notifier
    Set pending build status on Github commit.

    Requires the Jenkins :jenkins-plugins:`Github Plugin <github>`.

    Example:

    .. literalinclude:: /../../tests/builders/fixtures/github-notifier.yaml
       :language: yaml
    """
    XML.SubElement(xml_parent, "com.cloudbees.jenkins.GitHubSetCommitStatusBuilder")


def scan_build(registry, xml_parent, data):
    """yaml: scan-build
    This plugin allows you configure a build step that will execute the Clang
    scan-build static analysis tool against an XCode project.

    The scan-build report has to be generated in the directory
    ``${WORKSPACE}/clangScanBuildReports`` for the publisher to find it.

    Requires the Jenkins :jenkins-plugins:`Clang Scan-Build Plugin
    <clang-scanbuild>`.

    :arg str target: Provide the exact name of the XCode target you wish to
        have compiled and analyzed (required)
    :arg str target-sdk: Set the simulator version of a currently installed SDK
        (default iphonesimulator)
    :arg str config: Provide the XCode config you wish to execute scan-build
        against (default Debug)
    :arg str clang-install-name: Name of clang static analyzer to use (default
        '')
    :arg str xcode-sub-path: Path of XCode project relative to the workspace
        (default '')
    :arg str workspace: Name of workspace (default '')
    :arg str scheme: Name of scheme (default '')
    :arg str scan-build-args: Additional arguments to clang scan-build
        (default --use-analyzer Xcode)
    :arg str xcode-build-args: Additional arguments to XCode (default
        -derivedDataPath $WORKSPACE/build)
    :arg str report-folder: Folder where generated reports are located
        (>=1.7) (default clangScanBuildReports)

    Full Example:

    .. literalinclude:: /../../tests/builders/fixtures/scan-build-full.yaml
       :language: yaml

    Minimal Example:

    .. literalinclude::
       /../../tests/builders/fixtures/scan-build-minimal.yaml
       :language: yaml
    """
    p = XML.SubElement(
        xml_parent, "jenkins.plugins.clangscanbuild.ClangScanBuildBuilder"
    )
    p.set("plugin", "clang-scanbuild")

    mappings = [
        ("target", "target", None),
        ("target-sdk", "targetSdk", "iphonesimulator"),
        ("config", "config", "Debug"),
        ("clang-install-name", "clangInstallationName", ""),
        ("xcode-sub-path", "xcodeProjectSubPath", "myProj/subfolder"),
        ("workspace", "workspace", ""),
        ("scheme", "scheme", ""),
        ("scan-build-args", "scanbuildargs", "--use-analyzer Xcode"),
        ("xcode-build-args", "xcodebuildargs", "-derivedDataPath $WORKSPACE/build"),
        ("report-folder", "outputFolderName", "clangScanBuildReports"),
    ]
    helpers.convert_mapping_to_xml(p, data, mappings, fail_required=True)


def ssh_builder(registry, xml_parent, data):
    """yaml: ssh-builder
    Executes command on remote host

    Requires the Jenkins :jenkins-plugins:`SSH plugin <ssh>`.

    :arg str ssh-user-ip: user@ip:ssh_port of machine that was defined
        in jenkins according to SSH plugin instructions
    :arg str command: command to run on remote server

    Example:

    .. literalinclude:: /../../tests/builders/fixtures/ssh-builder.yaml
       :language: yaml
    """
    builder = XML.SubElement(xml_parent, "org.jvnet.hudson.plugins.SSHBuilder")

    mapping = [("ssh-user-ip", "siteName", None), ("command", "command", None)]
    helpers.convert_mapping_to_xml(builder, data, mapping, fail_required=True)


def sonar(registry, xml_parent, data):
    """yaml: sonar
    Invoke standalone Sonar analysis.

    Requires the Jenkins `Sonar Plugin
    <https://docs.sonarqube.org/latest/analysis/scan/sonarscanner-for-jenkins>`_.

    :arg str sonar-name: Name of the Sonar installation.
    :arg str sonar-scanner: Name of the Sonar Scanner.
    :arg str task: Task to run. (default '')
    :arg str project: Path to Sonar project properties file. (default '')
    :arg str properties: Sonar configuration properties. (default '')
    :arg str java-opts: Java options for Sonnar Runner. (default '')
    :arg str additional-arguments: additional command line arguments
        (default '')
    :arg str jdk: JDK to use (inherited from the job if omitted). (optional)

    Example:

    .. literalinclude:: /../../tests/builders/fixtures/sonar.yaml
       :language: yaml
    """
    sonar = XML.SubElement(xml_parent, "hudson.plugins.sonar.SonarRunnerBuilder")
    sonar.set("plugin", "sonar")
    XML.SubElement(sonar, "installationName").text = data["sonar-name"]
    mappings = [
        ("scanner-name", "sonarScannerName", ""),
        ("task", "task", ""),
        ("project", "project", ""),
        ("properties", "properties", ""),
        ("java-opts", "javaOpts", ""),
        ("additional-arguments", "additionalArguments", ""),
    ]
    helpers.convert_mapping_to_xml(sonar, data, mappings, fail_required=True)
    if "jdk" in data:
        XML.SubElement(sonar, "jdk").text = data["jdk"]


def xcode(registry, xml_parent, data):
    """yaml: xcode
    This step allows you to execute an xcode build step.

    Requires the Jenkins :jenkins-plugins:`Xcode Plugin <xcode-plugin>`.

    :arg str developer-profile: the jenkins credential id for a
        ios developer profile. (optional)
    :arg bool clean-build: if true will delete the build directories
        before invoking the build. (default false)
    :arg bool clean-test-reports: UNKNOWN. (default false)
    :arg bool archive: if true will generate an xcarchive of the specified
        scheme. A workspace and scheme are are also needed for archives.
        (default false)
    :arg str configuration: This is the name of the configuration
        as defined in the Xcode project. (default 'Release')
    :arg str configuration-directory: The value to use for
        CONFIGURATION_BUILD_DIR setting. (default '')
    :arg str target: Leave empty for all targets. (default '')
    :arg str sdk: Leave empty for default SDK. (default '')
    :arg str symroot: Leave empty for default SYMROOT. (default '')
    :arg str project-path: Relative path within the workspace
        that contains the xcode project file(s). (default '')
    :arg str project-file: Only needed if there is more than one
        project file in the Xcode Project Directory. (default '')
    :arg str build-arguments: Extra commandline arguments provided
        to the xcode builder. (default '')
    :arg str schema: Only needed if you want to compile for a
        specific schema instead of a target. (default '')
    :arg str workspace: Only needed if you want to compile a
        workspace instead of a project. (default '')
    :arg str profile: The relative path to the mobileprovision to embed,
        leave blank for no embedded profile. (default '')
    :arg str codesign-id: Override the code signing identity specified
        in the project. (default '')
    :arg bool allow-failing: if true will prevent this build step from
        failing if xcodebuild exits with a non-zero return code. (default
        false)
    :arg str version-technical: The value to use for CFBundleVersion.
        Leave blank to use project's technical number. (default '')
    :arg str version-marketing: The value to use for
        CFBundleShortVersionString. Leave blank to use project's
        marketing number. (default '')
    :arg str ipa-export-method: The export method of the .app to generate the
        .ipa file.  Should be one in 'development', 'ad-hoc', 'enterprise',
        or 'app-store'. (default '')
    :arg str ipa-version: A pattern for the ipa file name. You may use
        ${VERSION} and ${BUILD_DATE} (yyyy.MM.dd) in this string.
        (default '')
    :arg str ipa-output: The output directory for the .ipa file,
        relative to the build directory. (default '')
    :arg bool compile-bitcode: recompile from Bitcode when exporting the
        application to IPA. (default true)
    :arg bool upload-bitcode: include Bitcode when exporting applications to
        IPA. (default true)
    :arg bool upload-symbols: include symbols when exporting applications to
        IPA. (default true)
    :arg development-team-id: The ID of the Apple development team to use to
        sign the IPA (default '')
    :arg str keychain-name: The globally configured keychain to unlock for
        this build. (default '')
    :arg str keychain-path: The path of the keychain to use to sign the IPA.
        (default '')
    :arg str keychain-password: The password to use to unlock the keychain.
        (default '')
    :arg str keychain-unlock: Unlocks the keychain during use.
        (default false)
    :arg str bundle-id: The bundle identifier (App ID) for this provisioning
        profile (default '')
    :arg str provisioning-profile-uuid: The UUID of the provisioning profile
        associated to this bundle identifier. (default '')

    Example:

    .. literalinclude:: /../../tests/builders/fixtures/xcode.yaml
       :language: yaml
    """

    if data.get("developer-profile"):
        profile = XML.SubElement(xml_parent, "au.com.rayh." "DeveloperProfileLoader")
        mapping = [("developer-profile", "id", None)]
        helpers.convert_mapping_to_xml(profile, data, mapping, fail_required=False)

    xcode = XML.SubElement(xml_parent, "au.com.rayh.XCodeBuilder")

    mappings = [
        ("clean-build", "cleanBeforeBuild", False),
        ("clean-test-reports", "cleanTestReports", False),
        ("archive", "generateArchive", False),
        ("configuration", "configuration", "Release"),
        ("configuration-directory", "configurationBuildDir", ""),
        ("target", "target", ""),
        ("sdk", "sdk", ""),
        ("symroot", "symRoot", ""),
        ("project-path", "xcodeProjectPath", ""),
        ("project-file", "xcodeProjectFile", ""),
        ("build-arguments", "xcodebuildArguments", ""),
        ("schema", "xcodeSchema", ""),
        ("workspace", "xcodeWorkspaceFile", ""),
        ("profile", "embeddedProfileFile", ""),
        ("codesign-id", "codeSigningIdentity", ""),
        ("allow-failing", "allowFailingBuildResults", False),
    ]
    helpers.convert_mapping_to_xml(xcode, data, mappings, fail_required=True)

    version = XML.SubElement(xcode, "provideApplicationVersion")
    version_technical = XML.SubElement(xcode, "cfBundleVersionValue")
    version_marketing = XML.SubElement(xcode, "cfBundleShortVersionStringValue")

    if data.get("version-technical") or data.get("version-marketing"):
        version.text = "true"
        version_technical.text = data.get("version-technical", "")
        version_marketing.text = data.get("version-marketing", "")
    else:
        version.text = "false"

    XML.SubElement(xcode, "buildIpa").text = str(
        bool(data.get("ipa-version")) or False
    ).lower()

    valid_ipa_export_methods = ["", "ad-hoc", "app-store", "development"]
    mapping = [
        ("ipa-export-method", "ipaExportMethod", "", valid_ipa_export_methods),
        ("ipa-version", "ipaName", ""),
        ("ipa-output", "ipaOutputDirectory", ""),
        ("development-team-id", "developmentTeamID", ""),
        ("keychain-name", "keychainName", ""),
        ("keychain-path", "keychainPath", ""),
        ("keychain-password", "keychainPwd", ""),
        ("keychain-unlock", "unlockKeychain", False),
        ("compile-bitcode", "compileBitcode", True),
        ("upload-bitcode", "uploadBitcode", True),
        ("upload-symbols", "uploadSymbols", True),
    ]
    helpers.convert_mapping_to_xml(xcode, data, mapping, fail_required=True)

    has_provisioning_profiles = bool(data.get("provisioning-profiles"))
    XML.SubElement(xcode, "manualSigning").text = str(
        has_provisioning_profiles or False
    ).lower()
    if has_provisioning_profiles:
        provisioning_profiles_xml = XML.SubElement(xcode, "provisioningProfiles")
        mapping = [
            ("bundle-id", "provisioningProfileAppId", ""),
            ("provisioning-profile-uuid", "provisioningProfileUUID", ""),
        ]
        for provisioning_profile in data.get("provisioning-profiles"):
            provisioning_profile_xml = XML.SubElement(
                provisioning_profiles_xml, "au.com.rayh.ProvisioningProfile"
            )
            helpers.convert_mapping_to_xml(
                provisioning_profile_xml,
                provisioning_profile,
                mapping,
                fail_required=True,
            )


def sonatype_clm(registry, xml_parent, data):
    """yaml: sonatype-clm
    Requires the Jenkins :jenkins-wiki:`Sonatype CLM Plugin
    <Sonatype+CLM+%28formerly+Insight+for+CI%29>`.

    :arg str value: Select CLM application from a list of available CLM
        applications or specify CLM Application ID (default list)
    :arg str application-name: Determines the policy elements to associate
        with this build. (required)
    :arg str username: Username on the Sonatype CLM server. Leave empty to
        use the username configured at global level. (default '')
    :arg str password: Password on the Sonatype CLM server. Leave empty to
        use the password configured at global level. (default '')
    :arg bool fail-on-clm-server-failure: Controls the build outcome if there
        is a failure in communicating with the CLM server. (default false)
    :arg str stage: Controls the stage the policy evaluation will be run
        against on the CLM server. Valid stages: build, stage-release, release,
        operate. (default 'build')
    :arg str scan-targets: Pattern of files to include for scanning.
        (default '')
    :arg str module-excludes: Pattern of files to exclude. (default '')
    :arg str advanced-options: Options to be set on a case-by-case basis as
        advised by Sonatype Support. (default '')

    Minimal Example:

    .. literalinclude::
        /../../tests/builders/fixtures/sonatype-clm-minimal.yaml
       :language: yaml

    Full Example:

    .. literalinclude::
        /../../tests/builders/fixtures/sonatype-clm-full.yaml
       :language: yaml
    """
    clm = XML.SubElement(xml_parent, "com.sonatype.insight.ci.hudson.PreBuildScan")
    clm.set("plugin", "sonatype-clm-ci")
    SUPPORTED_VALUES = ["list", "manual"]
    SUPPORTED_STAGES = ["build", "stage-release", "release", "operate"]

    application_select = XML.SubElement(clm, "applicationSelectType")
    application_mappings = [
        ("value", "value", "list", SUPPORTED_VALUES),
        ("application-name", "applicationId", None),
    ]
    helpers.convert_mapping_to_xml(
        application_select, data, application_mappings, fail_required=True
    )

    path = XML.SubElement(clm, "pathConfig")
    path_mappings = [
        ("scan-targets", "scanTargets", ""),
        ("module-excludes", "moduleExcludes", ""),
        ("advanced-options", "scanProperties", ""),
    ]
    helpers.convert_mapping_to_xml(path, data, path_mappings, fail_required=True)

    mappings = [
        ("fail-on-clm-server-failure", "failOnClmServerFailures", False),
        ("stage", "stageId", "build", SUPPORTED_STAGES),
        ("username", "username", ""),
        ("password", "password", ""),
    ]
    helpers.convert_mapping_to_xml(clm, data, mappings, fail_required=True)


def beaker(registry, xml_parent, data):
    """yaml: beaker
    Execute a beaker build step.

    Requires the Jenkins :jenkins-plugins:`Beaker Builder Plugin
    <beaker-builder>`.

    :arg str content: Run job from string
        (Alternative: you can choose a path instead)
    :arg str path: Run job from file
        (Alternative: you can choose a content instead)
    :arg bool download-logs: Download Beaker log files (default false)

    Example:

    .. literalinclude:: ../../tests/builders/fixtures/beaker-path.yaml
       :language: yaml

    .. literalinclude:: ../../tests/builders/fixtures/beaker-content.yaml
       :language: yaml
    """
    beaker = XML.SubElement(
        xml_parent, "org.jenkinsci.plugins.beakerbuilder." "BeakerBuilder"
    )
    jobSource = XML.SubElement(beaker, "jobSource")
    if "content" in data and "path" in data:
        raise JenkinsJobsException("Use just one of 'content' or 'path'")
    elif "content" in data:
        jobSourceClass = "org.jenkinsci.plugins.beakerbuilder.StringJobSource"
        jobSource.set("class", jobSourceClass)
        XML.SubElement(jobSource, "jobContent").text = data["content"]
    elif "path" in data:
        jobSourceClass = "org.jenkinsci.plugins.beakerbuilder.FileJobSource"
        jobSource.set("class", jobSourceClass)
        XML.SubElement(jobSource, "jobPath").text = data["path"]
    else:
        raise JenkinsJobsException("Use one of 'content' or 'path'")

    XML.SubElement(beaker, "downloadFiles").text = str(
        data.get("download-logs", False)
    ).lower()


def cloudformation(registry, xml_parent, data):
    """yaml: cloudformation
    Create cloudformation stacks before running a build and optionally
    delete them at the end.

    Requires the Jenkins :jenkins-plugins:`AWS Cloudformation Plugin
    <jenkins-cloudformation-plugin>`.

    :arg list name: The names of the stacks to create (required)
    :arg str description: Description of the stack (optional)
    :arg str recipe: The cloudformation recipe file (required)
    :arg list parameters: List of key/value pairs to pass
        into the recipe, will be joined together into a comma separated
        string (optional)
    :arg int timeout: Number of seconds to wait before giving up creating
        a stack (default 0)
    :arg str access-key: The Amazon API Access Key (required)
    :arg str secret-key: The Amazon API Secret Key (required)
    :arg int sleep: Number of seconds to wait before continuing to the
        next step (default 0)
    :arg str region: The region to run cloudformation in (required)

        :region values:
            * **us-east-1**
            * **us-west-1**
            * **us-west-2**
            * **eu-central-1**
            * **eu-west-1**
            * **ap-southeast-1**
            * **ap-southeast-2**
            * **ap-northeast-1**
            * **sa-east-1**

    Example:

    .. literalinclude:: ../../tests/builders/fixtures/cloudformation.yaml
       :language: yaml
    """
    region_dict = helpers.cloudformation_region_dict()
    stacks = helpers.cloudformation_init(xml_parent, data, "CloudFormationBuildStep")
    for stack in data:
        helpers.cloudformation_stack(
            xml_parent, stack, "PostBuildStackBean", stacks, region_dict
        )


def jms_messaging(registry, xml_parent, data):
    """yaml: jms-messaging
    The JMS Messaging Plugin provides the following functionality:
     - A build trigger to submit jenkins jobs upon receipt
       of a matching message.
     - A builder that may be used to submit a message to the topic
       upon the completion of a job
     - A post-build action that may be used to submit a message to the topic
       upon the completion of a job


    JMS Messaging provider types supported:
        - ActiveMQ
        - FedMsg

    Requires the Jenkins :jenkins-plugins:`JMS Messaging Plugin Pipeline Plugin
    <jms-messaging>`.

    :arg str override-topic: If you need to override the default topic.
        (default '')
    :arg str provider-name: Name of message provider setup in the
        global config. (default '')
    :arg str msg-type: A message type
        (default 'CodeQualityChecksDone')
    :arg str msg-props: Message header to publish. (default '')
    :arg str msg-content: Message body to publish. (default '')


    Full Example:

    .. literalinclude::
        ../../tests/builders/fixtures/jms-messaging-full.yaml
       :language: yaml

    Minimal Example:

    .. literalinclude::
        ../../tests/builders/fixtures/jms-messaging-minimal.yaml
       :language: yaml
    """
    helpers.jms_messaging_common(
        xml_parent, "com.redhat.jenkins.plugins.ci." "CIMessageBuilder", data
    )


def openshift_build_verify(registry, xml_parent, data):
    r"""yaml: openshift-build-verify
    Performs the equivalent of an 'oc get builds` command invocation for the
    provided buildConfig key provided; once the list of builds are obtained,
    the state of the latest build is inspected for up to a minute to see if
    it has completed successfully.

    Requires the Jenkins :jenkins-plugins:`OpenShift Pipeline Plugin
    <openshift-pipeline>`.

    :arg str api-url: this would be the value you specify if you leverage the
        --server option on the OpenShift `oc` command.
        (default '\https://openshift.default.svc.cluster.local')
    :arg str bld-cfg: The value here should be whatever was the output
        form `oc project` when you created the BuildConfig you
        want to run a Build on (default 'frontend')
    :arg str namespace: If you run `oc get bc` for the project listed in
        "namespace", that is the value you want to put here. (default 'test')
    :arg str auth-token: The value here is what you supply with the --token
        option when invoking the OpenShift `oc` command. (default '')
    :arg bool verbose: This flag is the toggle for
        turning on or off detailed logging in this plug-in. (default false)

    Full Example:

    .. literalinclude::
        ../../tests/builders/fixtures/openshift-build-verify001.yaml
       :language: yaml

    Minimal Example:

    .. literalinclude::
        ../../tests/builders/fixtures/openshift-build-verify002.yaml
       :language: yaml
    """
    osb = XML.SubElement(
        xml_parent, "com.openshift.jenkins.plugins.pipeline." "OpenShiftBuildVerifier"
    )

    mapping = [
        # option, xml name, default value
        ("api-url", "apiURL", "https://openshift.default.svc.cluster.local"),
        ("bld-cfg", "bldCfg", "frontend"),
        ("namespace", "namespace", "test"),
        ("auth-token", "authToken", ""),
        ("verbose", "verbose", False),
    ]
    helpers.convert_mapping_to_xml(osb, data, mapping, fail_required=True)


def openshift_builder(registry, xml_parent, data):
    r"""yaml: openshift-builder
    Perform builds in OpenShift for the job.

    Requires the Jenkins :jenkins-plugins:`OpenShift Pipeline Plugin
    <openshift-pipeline>`.

    :arg str api-url: this would be the value you specify if you leverage the
        --server option on the OpenShift `oc` command.
        (default '\https://openshift.default.svc.cluster.local')
    :arg str bld-cfg: The value here should be whatever was the output
        form `oc project` when you created the BuildConfig you want to run a
        Build on (default 'frontend')
    :arg str namespace: If you run `oc get bc` for the project listed in
        "namespace", that is the value you want to put here. (default 'test')
    :arg str auth-token: The value here is what you supply with the --token
        option when invoking the OpenShift `oc` command. (default '')
    :arg str commit-ID: The value here is what you supply with the
        --commit option when invoking the
        OpenShift `oc start-build` command. (default '')
    :arg bool verbose: This flag is the toggle for
        turning on or off detailed logging in this plug-in. (default false)
    :arg str build-name: TThe value here is what you supply with the
        --from-build option when invoking the
        OpenShift `oc start-build` command. (default '')
    :arg bool show-build-logs: Indicates whether the build logs get dumped
        to the console of the Jenkins build. (default false)


    Full Example:

    .. literalinclude:: ../../tests/builders/fixtures/openshift-builder001.yaml
       :language: yaml

    Minimal Example:

    .. literalinclude:: ../../tests/builders/fixtures/openshift-builder002.yaml
       :language: yaml
    """
    osb = XML.SubElement(
        xml_parent, "com.openshift.jenkins.plugins.pipeline." "OpenShiftBuilder"
    )

    mapping = [
        # option, xml name, default value
        ("api-url", "apiURL", "https://openshift.default.svc.cluster.local"),
        ("bld-cfg", "bldCfg", "frontend"),
        ("namespace", "namespace", "test"),
        ("auth-token", "authToken", ""),
        ("commit-ID", "commitID", ""),
        ("verbose", "verbose", False),
        ("build-name", "buildName", ""),
        ("show-build-logs", "showBuildLogs", False),
    ]
    helpers.convert_mapping_to_xml(osb, data, mapping, fail_required=True)


def openshift_creator(registry, xml_parent, data):
    r"""yaml: openshift-creator
    Performs the equivalent of an oc create command invocation;
    this build step takes in the provided JSON or YAML text, and if it
    conforms to OpenShift schema, creates whichever
    OpenShift resources are specified.

    Requires the Jenkins :jenkins-plugins:`OpenShift Pipeline Plugin
    <openshift-pipeline>`.

    :arg str api-url: this would be the value you specify if you leverage the
        --server option on the OpenShift `oc` command.
        (default '\https://openshift.default.svc.cluster.local')
    :arg str jsonyaml: The JSON or YAML formatted text that conforms to
        the schema for defining the various OpenShift resources. (default '')
    :arg str namespace: If you run `oc get bc` for the project listed in
        "namespace", that is the value you want to put here. (default 'test')
    :arg str auth-token: The value here is what you supply with the --token
        option when invoking the OpenShift `oc` command. (default '')
    :arg bool verbose: This flag is the toggle for
        turning on or off detailed logging in this plug-in. (default false)

    Full Example:

    .. literalinclude::
        ../../tests/builders/fixtures/openshift-creator001.yaml
       :language: yaml

    Minimal Example:

    .. literalinclude::
        ../../tests/builders/fixtures/openshift-creator002.yaml
       :language: yaml
    """
    osb = XML.SubElement(
        xml_parent, "com.openshift.jenkins.plugins.pipeline." "OpenShiftCreator"
    )

    mapping = [
        # option, xml name, default value
        ("api-url", "apiURL", "https://openshift.default.svc.cluster.local"),
        ("jsonyaml", "jsonyaml", ""),
        ("namespace", "namespace", "test"),
        ("auth-token", "authToken", ""),
        ("verbose", "verbose", False),
    ]
    helpers.convert_mapping_to_xml(osb, data, mapping, fail_required=True)


def openshift_dep_verify(registry, xml_parent, data):
    r"""yaml: openshift-dep-verify
    Determines whether the expected set of DeploymentConfig's,
    ReplicationController's, and active replicas are present based on prior
    use of the scaler (2) and deployer (3) steps

    Requires the Jenkins :jenkins-plugins:`OpenShift Pipeline Plugin
    <openshift-pipeline>`.

    :arg str api-url: this would be the value you specify if you leverage the
        --server option on the OpenShift `oc` command.
        (default \https://openshift.default.svc.cluster.local\)
    :arg str dep-cfg: The value here should be whatever was the output
        form `oc project` when you created the BuildConfig you want to run a
        Build on (default frontend)
    :arg str namespace: If you run `oc get bc` for the project listed in
        "namespace", that is the value you want to put here. (default test)
    :arg int replica-count: The value here should be whatever the number
        of pods you want started for the deployment. (default 0)
    :arg str auth-token: The value here is what you supply with the --token
        option when invoking the OpenShift `oc` command. (default '')
    :arg bool verbose: This flag is the toggle for
        turning on or off detailed logging in this plug-in. (default false)

    Full Example:

    .. literalinclude::
        ../../tests/builders/fixtures/openshift-dep-verify001.yaml
       :language: yaml

    Minimal Example:

    .. literalinclude::
        ../../tests/builders/fixtures/openshift-dep-verify002.yaml
       :language: yaml
    """
    osb = XML.SubElement(
        xml_parent,
        "com.openshift.jenkins.plugins.pipeline." "OpenShiftDeploymentVerifier",
    )

    mapping = [
        # option, xml name, default value
        ("api-url", "apiURL", "https://openshift.default.svc.cluster.local"),
        ("dep-cfg", "depCfg", "frontend"),
        ("namespace", "namespace", "test"),
        ("replica-count", "replicaCount", 0),
        ("auth-token", "authToken", ""),
        ("verbose", "verbose", False),
    ]
    helpers.convert_mapping_to_xml(osb, data, mapping, fail_required=True)


def openshift_deployer(registry, xml_parent, data):
    r"""yaml: openshift-deployer
    Start a deployment in OpenShift for the job.

    Requires the Jenkins :jenkins-plugins:`OpenShift Pipeline Plugin
    <openshift-pipeline>`.

    :arg str api-url: this would be the value you specify if you leverage the
        --server option on the OpenShift `oc` command.
        (default '\https://openshift.default.svc.cluster.local')
    :arg str dep-cfg: The value here should be whatever was the output
        form `oc project` when you created the BuildConfig you want to run a
        Build on (default 'frontend')
    :arg str namespace: If you run `oc get bc` for the project listed in
        "namespace", that is the value you want to put here. (default 'test')
    :arg str auth-token: The value here is what you supply with the --token
        option when invoking the OpenShift `oc` command. (default '')
    :arg bool verbose: This flag is the toggle for
        turning on or off detailed logging in this plug-in. (default false)

    Full Example:

    .. literalinclude::
        ../../tests/builders/fixtures/openshift-deployer001.yaml
       :language: yaml

    Minimal Example:

    .. literalinclude::
        ../../tests/builders/fixtures/openshift-deployer002.yaml
       :language: yaml
    """
    osb = XML.SubElement(
        xml_parent, "com.openshift.jenkins.plugins.pipeline." "OpenShiftDeployer"
    )

    mapping = [
        # option, xml name, default value
        ("api-url", "apiURL", "https://openshift.default.svc.cluster.local"),
        ("dep-cfg", "depCfg", "frontend"),
        ("namespace", "namespace", "test"),
        ("auth-token", "authToken", ""),
        ("verbose", "verbose", False),
    ]
    helpers.convert_mapping_to_xml(osb, data, mapping, fail_required=True)


def openshift_img_tagger(registry, xml_parent, data):
    r"""yaml: openshift-img-tagger
    Performs the equivalent of an oc tag command invocation in order to
    manipulate tags for images in OpenShift ImageStream's

    Requires the Jenkins :jenkins-plugins:`OpenShift Pipeline Plugin
    <openshift-pipeline>`.

    :arg str api-url: this would be the value you specify if you leverage the
        --server option on the OpenShift `oc` command.
        (default '\https://openshift.default.svc.cluster.local')
    :arg str test-tag: The equivalent to the name supplied to a
        `oc get service` command line invocation.
        (default 'origin-nodejs-sample:latest')
    :arg str prod-tag: The equivalent to the name supplied to a
        `oc get service` command line invocation.
        (default 'origin-nodejs-sample:prod')
    :arg str namespace: If you run `oc get bc` for the project listed in
        "namespace", that is the value you want to put here. (default 'test')
    :arg str auth-token: The value here is what you supply with the --token
        option when invoking the OpenShift `oc` command. (default '')
    :arg bool verbose: This flag is the toggle for
        turning on or off detailed logging in this plug-in. (default false)

    Full Example:

    .. literalinclude::
        ../../tests/builders/fixtures/openshift-img-tagger001.yaml
       :language: yaml

    Minimal Example:

    .. literalinclude::
        ../../tests/builders/fixtures/openshift-img-tagger002.yaml
       :language: yaml
    """
    osb = XML.SubElement(
        xml_parent, "com.openshift.jenkins.plugins.pipeline." "OpenShiftImageTagger"
    )

    mapping = [
        # option, xml name, default value
        ("api-url", "apiURL", "https://openshift.default.svc.cluster.local"),
        ("test-tag", "testTag", "origin-nodejs-sample:latest"),
        ("prod-tag", "prodTag", "origin-nodejs-sample:prod"),
        ("namespace", "namespace", "test"),
        ("auth-token", "authToken", ""),
        ("verbose", "verbose", False),
    ]
    helpers.convert_mapping_to_xml(osb, data, mapping, fail_required=True)


def openshift_scaler(registry, xml_parent, data):
    r"""yaml: openshift-scaler
    Scale deployments in OpenShift for the job.

    Requires the Jenkins :jenkins-plugins:`OpenShift Pipeline Plugin
    <openshift-pipeline>`.

    :arg str api-url: this would be the value you specify if you leverage the
        --server option on the OpenShift `oc` command.
        (default '\https://openshift.default.svc.cluster.local')
    :arg str dep-cfg: The value here should be whatever was the output
        form `oc project` when you created the BuildConfig you want to run a
        Build on (default 'frontend')
    :arg str namespace: If you run `oc get bc` for the project listed in
        "namespace", that is the value you want to put here. (default 'test')
    :arg int replica-count: The value here should be whatever the number
        of pods you want started for the deployment. (default 0)
    :arg str auth-token: The value here is what you supply with the --token
        option when invoking the OpenShift `oc` command. (default '')
    :arg bool verbose: This flag is the toggle for
        turning on or off detailed logging in this plug-in. (default false)

    Full Example:

    .. literalinclude:: ../../tests/builders/fixtures/openshift-scaler001.yaml
       :language: yaml

    Minimal Example:

    .. literalinclude:: ../../tests/builders/fixtures/openshift-scaler002.yaml
       :language: yaml
    """
    osb = XML.SubElement(
        xml_parent, "com.openshift.jenkins.plugins.pipeline." "OpenShiftScaler"
    )

    mapping = [
        # option, xml name, default value
        ("api-url", "apiURL", "https://openshift.default.svc.cluster.local"),
        ("dep-cfg", "depCfg", "frontend"),
        ("namespace", "namespace", "test"),
        ("replica-count", "replicaCount", 0),
        ("auth-token", "authToken", ""),
        ("verbose", "verbose", False),
    ]
    helpers.convert_mapping_to_xml(osb, data, mapping, fail_required=True)


def openshift_svc_verify(registry, xml_parent, data):
    r"""yaml: openshift-svc-verify
    Verify a service is up in OpenShift for the job.

    Requires the Jenkins :jenkins-plugins:`OpenShift Pipeline Plugin
    <openshift-pipeline>`.

    :arg str api-url: this would be the value you specify if you leverage the
        --server option on the OpenShift `oc` command.
        (default '\https://openshift.default.svc.cluster.local')
    :arg str svc-name: The equivalent to the name supplied to a
        `oc get service` command line invocation. (default 'frontend')
    :arg str namespace: If you run `oc get bc` for the project listed in
        "namespace", that is the value you want to put here. (default 'test')
    :arg str auth-token: The value here is what you supply with the --token
        option when invoking the OpenShift `oc` command. (default '')
    :arg bool verbose: This flag is the toggle for
        turning on or off detailed logging in this plug-in. (default false)

    Full Example:

    .. literalinclude::
        ../../tests/builders/fixtures/openshift-svc-verify001.yaml
       :language: yaml

    Minimal Example:

    .. literalinclude::
        ../../tests/builders/fixtures/openshift-svc-verify002.yaml
       :language: yaml
    """
    osb = XML.SubElement(
        xml_parent, "com.openshift.jenkins.plugins.pipeline." "OpenShiftServiceVerifier"
    )

    mapping = [
        # option, xml name, default value
        ("api-url", "apiURL", "https://openshift.default.svc.cluster.local"),
        ("svc-name", "svcName", "frontend"),
        ("namespace", "namespace", "test"),
        ("auth-token", "authToken", ""),
        ("verbose", "verbose", False),
    ]
    helpers.convert_mapping_to_xml(osb, data, mapping, fail_required=True)


def runscope(registry, xml_parent, data):
    """yaml: runscope
    Execute a Runscope test.

    Requires the Jenkins :jenkins-plugins:`Runscope Plugin <runscope>`.

    :arg str test-trigger-url: Trigger URL for test. (required)
    :arg str access-token: OAuth Personal Access token. (required)
    :arg int timeout: Timeout for test duration in seconds. (default 60)

    Minimal Example:

    .. literalinclude:: /../../tests/builders/fixtures/runscope-minimal.yaml
       :language: yaml

    Full Example:

    .. literalinclude:: /../../tests/builders/fixtures/runscope-full.yaml
       :language: yaml
    """
    runscope = XML.SubElement(
        xml_parent, "com.runscope.jenkins.Runscope.RunscopeBuilder"
    )
    runscope.set("plugin", "runscope")

    mapping = [
        ("test-trigger-url", "triggerEndPoint", None),
        ("access-token", "accessToken", None),
        ("timeout", "timeout", 60),
    ]
    helpers.convert_mapping_to_xml(runscope, data, mapping, fail_required=True)


def description_setter(registry, xml_parent, data):
    """yaml: description-setter
    This plugin sets the description for each build,
    based upon a RegEx test of the build log file.

    Requires the Jenkins :jenkins-plugins:`Description Setter Plugin
    <description-setter>`.

    :arg str regexp: A RegEx which is used to scan the build log file
        (default '')
    :arg str description: The description to set on the build (optional)

    Example:

    .. literalinclude::
        /../../tests/builders/fixtures/description-setter001.yaml
       :language: yaml
    """

    descriptionsetter = XML.SubElement(
        xml_parent, "hudson.plugins.descriptionsetter.DescriptionSetterBuilder"
    )
    mapping = [("regexp", "regexp", "")]
    if "description" in data:
        mapping.append(("description", "description", None))
    helpers.convert_mapping_to_xml(descriptionsetter, data, mapping, fail_required=True)


def build_publish_docker_image(registry, xml_parent, data):
    """yaml: build-publish-docker-image
    Provides the ability to build projects with a Dockerfile and publish the
    resultant tagged image (repo) to the docker registry.

    Requires the Jenkins :jenkins-plugins:`CloudBees Docker Build and Publish
    plugin <docker-build-publish>`.

    :arg str docker-registry-url: URL to the Docker registry you are
        using (default '')
    :arg str image: Repository name to be applied to the resulting image
        in case of success (default '')
    :arg str docker-file-directory: Build step that sends a Dockerfile for
        building to docker host that used for this build run (default '')
    :arg bool push-on-success: Resulting docker image will be pushed to
        the registry (or registries) specified within the
        "Image" field (default false)
    :arg str push-credentials-id: Credentials to push to a private
        registry (default '')
    :arg bool clean-images: Option to clean local images (default false)
    :arg bool jenkins-job-delete: Attempt to remove images when jenkins
        deletes the run	(default false)
    :arg str cloud: Cloud to use to build image	(default '')

    Minimal example:

    .. literalinclude::
        /../../tests/builders/fixtures/build-publish-docker-image-minimal.yaml

    Full example:

    .. literalinclude::
        /../../tests/builders/fixtures/build-publish-docker-image-full.yaml
    """
    dbp = XML.SubElement(
        xml_parent,
        "com.nirima.jenkins.plugins.docker.builder" ".DockerBuilderPublisher",
    )
    dbp.set("plugin", "docker-plugin")

    from_registry = XML.SubElement(dbp, "fromRegistry")
    from_registry.set("plugin", "docker-commons")
    from_registry_mapping = [("docker-registry-url", "url", "")]
    helpers.convert_mapping_to_xml(
        from_registry, data, from_registry_mapping, fail_required=False
    )

    tags = XML.SubElement(dbp, "tags")
    XML.SubElement(tags, "string").text = data.get("image", "")

    mapping = [
        ("docker-file-directory", "dockerFileDirectory", ""),
        ("push-on-success", "pushOnSuccess", False),
        ("push-credentials-id", "pushCredentialsId", ""),
        ("clean-images", "cleanImages", False),
        ("jenkins-job-delete", "cleanupWithJenkinsJobDelete", False),
        ("cloud", "cloud", ""),
    ]
    helpers.convert_mapping_to_xml(dbp, data, mapping, fail_required=False)


def docker_build_publish(parse, xml_parent, data):
    """yaml: docker-build-publish
    Provides the ability to build projects with a Dockerfile, and publish the
    resultant tagged image (repo) to the docker registry.

    Requires the Jenkins :jenkins-plugins:`Docker build publish Plugin
    <docker-build-publish>`.

    :arg str repo-name: Name of repository to push to.
    :arg str repo-tag: Tag for image. (default '')
    :arg dict server: The docker daemon (optional)

        * **uri** (str): Define the docker server to use. (optional)
        * **credentials-id** (str): ID of credentials to use to connect
          (optional)
    :arg dict registry: Registry to push to

        * **url** (str) repository url to use (optional)
        * **credentials-id** (str): ID of credentials to use to connect
          (optional)
    :arg bool no-cache: If build should be cached. (default false)
    :arg bool no-force-pull: Don't update the source image before building when
        it exists locally. (default false)
    :arg bool skip-build: Do not build the image. (default false)
    :arg bool skip-decorate: Do not decorate the build name. (default false)
    :arg bool skip-tag-latest: Do not tag this build as latest. (default false)
    :arg bool skip-push: Do not push. (default false)
    :arg str file-path: Path of the Dockerfile. (default '')
    :arg str build-context: Project root path for the build, defaults to the
        workspace if not specified. (default '')
    :arg bool create-fingerprint: If enabled, the plugin will create
        fingerprints after the build of each image. (default false)
    :arg str build-args: Additional build arguments passed to
        docker build (default '')
    :arg bool force-tag: Force tag replacement when tag already
        exists (default false)

    Minimal example:

    .. literalinclude:: /../../tests/builders/fixtures/docker-builder001.yaml

    Full example:

    .. literalinclude:: /../../tests/builders/fixtures/docker-builder002.yaml
    """
    db = XML.SubElement(xml_parent, "com.cloudbees.dockerpublish.DockerBuilder")
    db.set("plugin", "docker-build-publish")

    mapping = [
        ("repo-name", "repoName", None),
        ("repo-tag", "repoTag", ""),
        ("no-cache", "noCache", False),
        ("no-force-pull", "noForcePull", False),
        ("skip-build", "skipBuild", False),
        ("skip-decorate", "skipDecorate", False),
        ("skip-tag-latest", "skipTagLatest", False),
        ("skip-push", "skipPush", False),
        ("file-path", "dockerfilePath", ""),
        ("build-context", "buildContext", ""),
        ("create-fingerprint", "createFingerprint", False),
        ("build-args", "buildAdditionalArgs", ""),
        ("force-tag", "forceTag", False),
    ]
    helpers.convert_mapping_to_xml(db, data, mapping, fail_required=True)

    mapping = []
    if "server" in data:
        server = XML.SubElement(db, "server")
        server.set("plugin", "docker-commons")
        server_data = data["server"]
        if "credentials-id" in server_data:
            mapping.append(("credentials-id", "credentialsId", None))

        if "uri" in server_data:
            mapping.append(("uri", "uri", None))
        helpers.convert_mapping_to_xml(server, server_data, mapping, fail_required=True)

    mappings = []
    if "registry" in data:
        registry = XML.SubElement(db, "registry")
        registry.set("plugin", "docker-commons")
        registry_data = data["registry"]
        if "credentials-id" in registry_data:
            mappings.append(("credentials-id", "credentialsId", None))

        if "url" in registry_data:
            mappings.append(("url", "url", None))
        helpers.convert_mapping_to_xml(
            registry, registry_data, mappings, fail_required=True
        )


def docker_pull_image(registry, xml_parent, data):
    """yaml: docker-pull-image
    Provides integration between Jenkins and Docker Hub, utilizing a
    Docker Hub hook to trigger one (or more) Jenkins job(s).

    Requires the Jenkins :jenkins-plugins:`CloudBees Docker Hub Notification
    <dockerhub-notification>`.

    :arg str image: Image ID on DockerHub (default '')
    :arg str docker-registry-url: URL to the Docker registry
        you are using (default '')
    :arg str credentials-id: Registry credentials (default '')

    Minimal example:

    .. literalinclude::
        /../../tests/builders/fixtures/docker-pull-image-minimal.yaml

    Full example:

    .. literalinclude::
        /../../tests/builders/fixtures/docker-pull-image-full.yaml
    """
    docker_pull_image = XML.SubElement(
        xml_parent,
        "org.jenkinsci.plugins.registry." "notification.DockerPullImageBuilder",
    )
    docker_pull_image.set("plugin", "dockerhub-notification")
    registry = XML.SubElement(docker_pull_image, "registry")
    registry.set("plugin", "docker-commons")
    mapping = [("image", "image", "")]
    helpers.convert_mapping_to_xml(
        docker_pull_image, data, mapping, fail_required=False
    )
    registry_mapping = [
        ("docker-registry-url", "url", ""),
        ("credentials-id", "credentialsId", ""),
    ]
    helpers.convert_mapping_to_xml(
        registry, data, registry_mapping, fail_required=False
    )


def build_name_setter(registry, xml_parent, data):
    """yaml: build-name-setter
    Define Build Name Setter options which allows your build name to be
    updated during the build process.

    Requires the Jenkins :jenkins-plugins:`Build Name Setter Plugin
    <build-name-setter>`.

    :arg str name: Filename to use for Build Name Setter, only used if
        file bool is true. (default 'version.txt')
    :arg str template: Macro Template string, only used if macro
        bool is true. (default '#${BUILD_NUMBER}')
    :arg bool file: Read from named file (default false)
    :arg bool macro: Read from macro template (default false)
    :arg bool macro-first: Insert macro first (default false)

    File Example:

    .. literalinclude::
        /../../tests/builders/fixtures/build-name-setter001.yaml
       :language: yaml

    Macro Example:

    .. literalinclude::
        /../../tests/builders/fixtures/build-name-setter002.yaml
       :language: yaml
    """
    build_name_setter = XML.SubElement(
        xml_parent, "org.jenkinsci.plugins.buildnameupdater.BuildNameUpdater"
    )
    mapping = [
        ("name", "buildName", "version.txt"),
        ("template", "macroTemplate", "#${BUILD_NUMBER}"),
        ("file", "fromFile", False),
        ("macro", "fromMacro", False),
        ("macro-first", "macroFirst", False),
    ]
    helpers.convert_mapping_to_xml(build_name_setter, data, mapping, fail_required=True)


def nexus_artifact_uploader(registry, xml_parent, data):
    """yaml: nexus-artifact-uploader
    To upload result of a build as an artifact in Nexus without the need of
    Maven.

    Requires the Jenkins :jenkins-plugins:`Nexus Artifact Uploader Plugin
    <nexus-artifact-uploader>`.

    :arg str protocol: Protocol to use to connect to Nexus (default https)
    :arg str nexus_url: Nexus url (without protocol) (default '')
    :arg str nexus_user: Username to upload artifact to Nexus (default '')
    :arg str nexus_password: Password to upload artifact to Nexus
        (default '')
    :arg str group_id: GroupId to set for the artifact to upload
        (default '')
    :arg str artifact_id: ArtifactId to set for the artifact to upload
        (default '')
    :arg str version: Version to set for the artifact to upload
        (default '')
    :arg str packaging: Packaging to set for the artifact to upload
        (default '')
    :arg str type: Type to set for the artifact to upload (default '')
    :arg str classifier: Classifier to set for the artifact to upload
        (default '')
    :arg str repository: In which repository to upload the artifact
        (default '')
    :arg str file: File which will be the uploaded artifact (default '')
    :arg str credentials_id: Credentials to use (instead of password)
        (default '')

    File Example:

    .. literalinclude::
        /../../tests/builders/fixtures/nexus_artifact_uploader001.yaml
       :language: yaml
    """
    nexus_artifact_uploader = XML.SubElement(
        xml_parent, "sp.sd.nexusartifactuploader.NexusArtifactUploader"
    )
    mapping = [
        ("protocol", "protocol", "https"),
        ("nexus_url", "nexusUrl", ""),
        ("nexus_user", "nexusUser", ""),
        ("nexus_password", "nexusPassword", ""),
        ("group_id", "groupId", ""),
        ("artifact_id", "artifactId", ""),
        ("version", "version", ""),
        ("packaging", "packaging", ""),
        ("type", "type", ""),
        ("classifier", "classifier", ""),
        ("repository", "repository", ""),
        ("file", "file", ""),
        ("credentials_id", "credentialsId", ""),
    ]
    helpers.convert_mapping_to_xml(
        nexus_artifact_uploader, data, mapping, fail_required=True
    )


def nexus_iq_policy_evaluator(registry, xml_parent, data):
    """yaml: nexus-iq-policy-evaluator
    Integrates the Nexus Lifecycle into a Jenkins job.
    This function triggers 'Invokes Nexus Policy Evaluation'.

    Requires the Jenkins :jenkins-plugins:`Nexus Platform Plugin
    <nexus-jenkins-plugin>`.

    :arg str stage: Controls the stage the policy evaluation will be
        run against on the Nexus IQ Server (required)

        :stage values:
            * **build**
            * **stage-release**
            * **release**
            * **operate**
    :arg dict application-type: Specifies an IQ Application (default manual)

        :application-type values:
            * **manual**
            * **selected**
    :arg str application-id: Specify the IQ Application ID (required)
    :arg list scan-patterns: List of Ant-style patterns relative to the
        workspace root that denote files/archives to be scanned (default [])
    :arg bool fail-build-network-error: Controls the build outcome if there
        is a failure in communicating with the Nexus IQ Server (default false)

    Minimal Example:

    .. literalinclude::
        /../../tests/builders/fixtures/nexus-iq-policy-evaluator-minimal.yaml
       :language: yaml

    Full Example:

    .. literalinclude::
        /../../tests/builders/fixtures/nexus-iq-policy-evaluator-full.yaml
       :language: yaml
    """
    nexus_iq_policy_evaluator = XML.SubElement(
        xml_parent, "org.sonatype.nexus.ci.iq.IqPolicyEvaluatorBuildStep"
    )

    format_dict = {
        "stage": "com__sonatype__nexus__ci__iq__IqPolicyEvaluator____iqStage",
        "fone": "com__sonatype__nexus__ci__iq__IqPolicyEvaluator"
        "____failBuildOnNetworkError",
    }

    valid_stages = ["build", "release", "stage-release", "operate"]
    mapping = [
        ("stage", format_dict.get("stage"), None, valid_stages),
        ("fail-build-network-error", format_dict.get("fone"), False),
    ]
    helpers.convert_mapping_to_xml(
        nexus_iq_policy_evaluator, data, mapping, fail_required=True
    )

    application_type_label = data.get("application-type", "manual").lower()
    application_type_label_dict = {
        "manual": "org.sonatype.nexus.ci.iq.ManualApplication",
        "selected": "org.sonatype.nexus.ci.iq.SelectedApplication",
    }
    if application_type_label not in application_type_label_dict:
        raise InvalidAttributeError(
            application_type_label,
            application_type_label,
            application_type_label_dict.keys(),
        )

    application_type_tag = XML.SubElement(
        nexus_iq_policy_evaluator,
        "com__sonatype__nexus__ci__iq__IqPolicyEvaluator____iqApplication",
    )
    application_type_tag.set(
        "class", application_type_label_dict[application_type_label]
    )

    mapping = [("application-id", "applicationId", None)]
    helpers.convert_mapping_to_xml(
        application_type_tag, data, mapping, fail_required=True
    )

    scan_pattern_list = data.get("scan-patterns", [])
    iq_scan_pattern_tag = XML.SubElement(
        nexus_iq_policy_evaluator,
        "com__sonatype__nexus__ci__iq" "__IqPolicyEvaluator____iqScanPatterns",
    )

    for scan_pattern in scan_pattern_list:
        scan_pattern_tag = XML.SubElement(
            iq_scan_pattern_tag, "org.sonatype.nexus.ci.iq.ScanPattern"
        )
        XML.SubElement(scan_pattern_tag, "scanPattern").text = scan_pattern


def nexus_repo_manager(registry, xml_parent, data):
    """yaml: nexus-repo-manager
    Allows for artifacts selected in Jenkins packages to be
    available in Nexus Repository Manager.

    Requires the Jenkins :jenkins-plugins:`Nexus Platform Plugin
    <nexus-jenkins-plugin>`.

    :arg str instance-id: The ID of the Nexus Instance (required)
    :arg str repo-id: The ID of the Nexus Repository (required)

    Minimal Example:

    .. literalinclude::
        /../../tests/builders/fixtures/nexus-repo-manager-minimal.yaml
       :language: yaml
    """
    nexus_repo_manager = XML.SubElement(
        xml_parent, "org.sonatype.nexus.ci." "nxrm.NexusPublisherBuildStep"
    )
    mapping = [
        ("instance-id", "nexusInstanceId", None),
        ("repo-id", "nexusRepositoryId", None),
    ]
    helpers.convert_mapping_to_xml(
        nexus_repo_manager, data, mapping, fail_required=True
    )


def ansible_playbook(parser, xml_parent, data):
    """yaml: ansible-playbook
    This plugin allows you to execute Ansible tasks as a job build step.

    Requires the Jenkins :jenkins-plugins:`Ansible Plugin <ansible>`.

    :arg str playbook: Path to the ansible playbook file. The path can be
        absolute or relative to the job workspace. (required)
    :arg str inventory-type: The inventory file form (default `path`)

        :inventory-type values:
            * **path**
            * **content**
            * **do-not-specify**

    :arg dict inventory: Inventory data, depends on inventory-type

        :inventory-type == path:
            * **path** (`str`) -- Path to inventory file.

        :inventory-type == content:
            * **content** (`str`) -- Content of inventory file.
            * **dynamic** (`bool`) -- Dynamic inventory is used (default false)

    :arg str hosts: Further limit selected hosts to an additional pattern
        (default '')
    :arg str tags-to-run: Only run plays and tasks tagged with these values
        (default '')
    :arg str tags-to-skip: Only run plays and tasks whose tags do not match
        these values (default '')
    :arg str task-to-start-at: Start the playbook at the task matching this
        name (default '')
    :arg int workers: Specify number of parallel processes to use (default 5)
    :arg str credentials-id: The ID of credentials for the SSH connections.
        Only private key authentication is supported (default '')
    :arg str vault-credentials-id: The ID of credentials for the vault
        decryption (default '')
    :arg bool sudo: Run operations with sudo. It works only when the remote
        user is sudoer with nopasswd option (default false)
    :arg str sudo-user: Desired sudo user. "root" is used when this field is
        empty. (default '')
    :arg bool unbuffered-output: Skip standard output buffering for the ansible
        process. The ansible output is directly rendered into the Jenkins
        console. This option can be useful for long running operations.
        (default true)
    :arg bool colorized-output: Check this box to allow ansible to render ANSI
        color codes in the Jenkins console. (default false)
    :arg bool disable-host-key-checking: Check this box to disable the
        validation of the hosts SSH server keys. (>= 1.0) (default false)
    :arg str additional-parameters: Any additional parameters to pass to the
        ansible command. (default '')
    :arg list variables: List of extra variables to be passed to ansible.
        (optional)

        :variable item:
            * **name** (`str`) -- Name of variable (required)
            * **value** (`str`) -- Desired value (default '')
            * **hidden** (`bool`) -- Hide variable in build log (default false)

    Outdated Options for versions >= 1.0 of plugin:

    :arg bool host-key-checking: Outdated, replaced with disable-host-key-checking.
        Check this box to enforce the validation of the hosts SSH server keys.
        (< 1.0) (default true)

    Example:

    .. literalinclude::
        /../../tests/builders/fixtures/ansible-playbook001.yaml
       :language: yaml

    OR

    .. literalinclude::
        /../../tests/builders/fixtures/ansible-playbook002.yaml
       :language: yaml

    Example(s) versions < 1.0:

    .. literalinclude::
        /../../tests/builders/fixtures/ansible-playbook005.yaml
       :language: yaml
    """
    plugin = XML.SubElement(
        xml_parent, "org.jenkinsci.plugins.ansible.AnsiblePlaybookBuilder"
    )
    try:
        XML.SubElement(plugin, "playbook").text = str(data["playbook"])
    except KeyError as ex:
        raise MissingAttributeError(ex)

    inventory_types = ("path", "content", "do-not-specify")
    inventory_type = str(data.get("inventory-type", inventory_types[0])).lower()

    inventory = XML.SubElement(plugin, "inventory")
    inv_data = data.get("inventory", {})
    if inventory_type == "path":
        inventory.set("class", "org.jenkinsci.plugins.ansible.InventoryPath")
        try:
            path = inv_data["path"]
        except KeyError:
            raise MissingAttributeError("inventory['path']")
        XML.SubElement(inventory, "path").text = path
    elif inventory_type == "content":
        inventory.set("class", "org.jenkinsci.plugins.ansible.InventoryContent")
        try:
            content = inv_data["content"]
        except KeyError:
            raise MissingAttributeError("inventory['content']")
        XML.SubElement(inventory, "content").text = content
        XML.SubElement(inventory, "dynamic").text = str(
            inv_data.get("dynamic", False)
        ).lower()
    elif inventory_type == "do-not-specify":
        inventory.set("class", "org.jenkinsci.plugins.ansible.InventoryDoNotSpecify")
    else:
        raise InvalidAttributeError("inventory-type", inventory_type, inventory_types)
    XML.SubElement(plugin, "limit").text = data.get("hosts", "")
    XML.SubElement(plugin, "tags").text = data.get("tags-to-run", "")
    XML.SubElement(plugin, "skippedTags").text = data.get("tags-to-skip", "")
    XML.SubElement(plugin, "startAtTask").text = data.get("task-to-start-at", "")
    XML.SubElement(plugin, "credentialsId").text = data.get("credentials-id", "")
    XML.SubElement(plugin, "vaultCredentialsId").text = data.get(
        "vault-credentials-id", ""
    )
    if data.get("sudo", False):
        XML.SubElement(plugin, "sudo").text = "true"
        XML.SubElement(plugin, "sudoUser").text = data.get("sudo-user", "")
    else:
        XML.SubElement(plugin, "sudo").text = "false"
    if data.get("become", False):
        XML.SubElement(plugin, "become").text = "true"
        XML.SubElement(plugin, "becomeUser").text = data.get("become-user", "")
    else:
        XML.SubElement(plugin, "become").text = "false"
    XML.SubElement(plugin, "forks").text = str(data.get("workers", "5"))
    XML.SubElement(plugin, "unbufferedOutput").text = str(
        data.get("unbuffered-output", True)
    ).lower()
    XML.SubElement(plugin, "colorizedOutput").text = str(
        data.get("colorized-output", False)
    ).lower()
    XML.SubElement(plugin, "disableHostKeyChecking").text = str(
        data.get("disable-host-key-checking", False)
    ).lower()
    XML.SubElement(plugin, "hostKeyChecking").text = str(
        data.get("host-key-checking", True)
    ).lower()
    XML.SubElement(plugin, "additionalParameters").text = str(
        data.get("additional-parameters", "")
    )
    # Following option is not available from UI
    XML.SubElement(plugin, "copyCredentialsInWorkspace").text = "false"
    variables = data.get("variables", [])
    if variables:
        if not is_sequence(variables):
            raise InvalidAttributeError(
                "variables", variables, "list(dict(name, value, hidden))"
            )
        variables_elm = XML.SubElement(plugin, "extraVars")
        for idx, values in enumerate(variables):
            if not hasattr(values, "keys"):
                raise InvalidAttributeError(
                    "variables[%s]" % idx, values, "dict(name, value, hidden)"
                )
            try:
                var_name = values["name"]
            except KeyError:
                raise MissingAttributeError("variables[%s]['name']" % idx)
            value_elm = XML.SubElement(
                variables_elm, "org.jenkinsci.plugins.ansible.ExtraVar"
            )
            XML.SubElement(value_elm, "key").text = var_name
            XML.SubElement(value_elm, "value").text = values.get("value", "")
            XML.SubElement(value_elm, "hidden").text = str(
                values.get("hidden", False)
            ).lower()


def nodejs(parser, xml_parent, data):
    """yaml: nodejs
    This plugin allows you to execute NodeJS scripts as a job build step.

    Requires the Jenkins :jenkins-plugins:`NodeJS Plugin <nodejs>`.

    :arg str name: NodeJS installation name
    :arg str script: NodeJS script (required)
    :arg str config-id: ID of npmrc config file, which is the
        last field (a 32-digit hexadecimal code) of the path of URL visible
        after you clicked the file under Jenkins Managed Files.

    Minimal Example:

    .. literalinclude::
        ../../tests/builders/fixtures/nodejs-minimal.yaml
       :language: yaml

    Full Example:

    .. literalinclude::
        ../../tests/builders/fixtures/nodejs-full.yaml
       :language: yaml
    """
    nodejs = XML.SubElement(
        xml_parent, "jenkins.plugins.nodejs.NodeJSCommandInterpreter"
    )
    mapping = [("script", "command", None)]

    mapping_opt = [
        ("name", "nodeJSInstallationName", None),
        ("config-id", "configId", None),
    ]

    helpers.convert_mapping_to_xml(nodejs, data, mapping, fail_required=True)
    helpers.convert_mapping_to_xml(nodejs, data, mapping_opt, fail_required=False)


def xunit(registry, xml_parent, data):
    """yaml: xunit
    Process tests results.

    Requires the Jenkins :jenkins-plugins:`xUnit Plugin <xunit>`.

    :arg str thresholdmode: Whether thresholds represents an absolute number
        of tests or a percentage. Either 'number' or 'percent'. (default
        'number')
    :arg list thresholds: Thresholds for both 'failed' and 'skipped' tests.

        :threshold (`dict`): Threshold values to set, where missing, xUnit
            should default to an internal value of 0. Each test threshold
            should contain the following:

            * **unstable** (`int`)
            * **unstablenew** (`int`)
            * **failure** (`int`)
            * **failurenew** (`int`)

    :arg int test-time-margin: Give the report time margin value in ms, before
        to fail if not new unless the option **requireupdate** is set for the
        configured framework. (default 3000)
    :arg list types: Frameworks to configure, and options. Supports the
        following: ``aunit``, ``boosttest``, ``checktype``, ``cpptest``,
        ``cppunit``, ``ctest``, ``dotnettest``, ``embunit``, ``fpcunit``,
        ``gtest``, ``junit``, ``mstest``, ``nunit``, ``phpunit``, ``tusar``,
        ``unittest``, and ``valgrind``.

        The 'custom' type is not supported.

        :type (`dict`): each type can be configured using the following:

            * **pattern** (`str`): An Ant pattern to look for Junit result
              files, relative to the workspace root (default '')
            * **requireupdate** (`bool`): fail the build whenever fresh tests
              results have not been found (default true).
            * **deleteoutput** (`bool`): delete temporary JUnit files
              (default true).
            * **skip-if-no-test-files** (`bool`): Skip parsing this xUnit type
              report if there are no test reports files (default false).
            * **stoponerror** (`bool`): Fail the build whenever an error occur
              during a result file processing (default true).

    Minimal Example:

    .. literalinclude::
        /../../tests/builders/fixtures/xunit-minimal.yaml
       :language: yaml

    Full Example:

    .. literalinclude::
        /../../tests/builders/fixtures/xunit-full.yaml
       :language: yaml

    """
    logger = logging.getLogger(__name__)
    xunit = XML.SubElement(xml_parent, "org.jenkinsci.plugins.xunit.XUnitBuilder")
    xunit.set("plugin", "xunit")

    # Map our internal types to the XML element names used by Jenkins plugin
    types_to_plugin_types = {
        "aunit": "AUnitJunitHudsonTestType",
        "boosttest": "BoostTestJunitHudsonTestType",
        "checktype": "CheckType",
        "cpptest": "CppTestJunitHudsonTestType",
        "cppunit": "CppUnitJunitHudsonTestType",
        "ctest": "CTestType",
        "dotnettest": "XUnitDotNetTestType",  # since plugin v1.93
        "embunit": "EmbUnitType",  # since plugin v1.84
        "fpcunit": "FPCUnitJunitHudsonTestType",
        "gtest": "GoogleTestType",
        "junit": "JUnitType",
        "mstest": "MSTestJunitHudsonTestType",
        "nunit": "NUnitJunitHudsonTestType",
        "phpunit": "PHPUnitJunitHudsonTestType",
        "tusar": "TUSARJunitHudsonTestType",
        "unittest": "UnitTestJunitHudsonTestType",
        "valgrind": "ValgrindJunitHudsonTestType",
        # FIXME should implement the 'custom' type
    }
    implemented_types = types_to_plugin_types.keys()  # shortcut

    # Unit framework we are going to generate xml for
    supported_types = []

    for configured_type in data["types"]:
        type_name = next(iter(configured_type.keys()))
        if type_name not in implemented_types:
            logger.warning("Requested xUnit type '%s' is not yet supported", type_name)
        else:
            # Append for generation
            supported_types.append(configured_type)

    # Generate XML for each of the supported framework types
    xmltypes = XML.SubElement(xunit, "types")
    mappings = [
        ("pattern", "pattern", ""),
        ("requireupdate", "failIfNotNew", True),
        ("deleteoutput", "deleteOutputFiles", True),
        ("skip-if-no-test-files", "skipNoTestFiles", False),
        ("stoponerror", "stopProcessingIfError", True),
    ]
    for supported_type in supported_types:
        framework_name = next(iter(supported_type.keys()))
        xmlframework = XML.SubElement(xmltypes, types_to_plugin_types[framework_name])

        helpers.convert_mapping_to_xml(
            xmlframework, supported_type[framework_name], mappings, fail_required=True
        )

    xmlthresholds = XML.SubElement(xunit, "thresholds")
    for t in data.get("thresholds", []):
        if not ("failed" in t or "skipped" in t):
            logger.warning("Unrecognized threshold, should be 'failed' or 'skipped'")
            continue
        elname = (
            "org.jenkinsci.plugins.xunit.threshold.%sThreshold"
            % next(iter(t.keys())).title()
        )
        el = XML.SubElement(xmlthresholds, elname)
        for threshold_name, threshold_value in next(iter(t.values())).items():
            # Normalize and craft the element name for this threshold
            elname = "%sThreshold" % threshold_name.lower().replace("new", "New")
            XML.SubElement(el, elname).text = str(threshold_value)

    # Whether to use percent of exact number of tests.
    # Thresholdmode is either:
    # - 1 : absolute (number of tests), default.
    # - 2 : relative (percentage of tests)
    thresholdmode = "1"
    if "percent" == data.get("thresholdmode", "number"):
        thresholdmode = "2"
    XML.SubElement(xunit, "thresholdMode").text = thresholdmode

    extra_config = XML.SubElement(xunit, "extraConfiguration")
    XML.SubElement(extra_config, "testTimeMargin").text = str(
        data.get("test-time-margin", "3000")
    )