Group API - create/update Variable missing `variable_type` and `environment_scope`
Looking at the HTTP API docs for [Group level variables|https://docs.gitlab.com/ee/api/group_level_variables.html] and it appears to support both a variable_type and a environment_scope. The two fields do not appear in the [Java API|https://javadoc.io/static/org.gitlab4j/gitlab4j-api/4.19.0/org/gitlab4j/api/GroupApi.html#createVariable-java.lang.Object-java.lang.String-java.lang.String-java.lang.Boolean-java.lang.Boolean-].
Is there a reason they are no included?
Thank you, Michael
I have encountered the same problem and came up with the following workaround. It works for me.
GitLabApi gitLabApi = GitLabApi.oauth2Login("yourUrl", "yourUsername", "yourPassword");
GroupApi groupApi = gitLabApi.getGroupApi();
org.gitlab4j.api.models.Group group = ... // define the group within which we will create variables
Object groupIdOrPath = groupApi.getGroupIdOrPath(group);
// build your variable
Form variable = new GitLabApiForm()
.withParam("key", "key_value", true)
.withParam("value", "value", true)
.withParam("variable_type", Variable.Type.ENV_VAR)
.withParam("protected", false)
.withParam("masked", false)
.withParam("environment_scope", "*");
// yeah, we need some reflection here
Method method = AbstractApi.class.getDeclaredMethod(
"post", Response.Status.class, jakarta.ws.rs.core.Form.class, Object[].class);
method.setAccessible(true);
// API call actually here
Response response = (Response) method.invoke(groupApi, Response.Status.CREATED, variable,
new Object[]{"groups", groupIdOrPath, "variables"});
Variable created = response.readEntity(Variable.class);
However, it is not at all clear why this functionality is missing from the Group API. It seems to be just an omission.